Re: Custom error handler for Seaside expiration and AJAX errors [ WAS ] Re: [AJAX] #script: & #html: vs #onSuccess: & #load & #html:
"Cyril Ferlicot D." <[email protected]>
| Newsgroups | gmane.comp.lang.smalltalk.squeak.seaside |
|---|---|
| Message-ID | <[email protected]> |
Le 24/09/2016 à 15:05, Mariano Martinez Peck a écrit :
> Hi Cyril,
>
> For seaside expiration I do not hook on EACH ajax call but with a global
> handler:
>
> html document addLoadScript: (html jQuery document
> onAjaxError: (self ajaxErrorHandler
> asFunction: #('event' 'jqxhr' 'settings' 'exception'))).
>
>
> Note that this handler will take care of seaside expiration as well as
> errors in either rendering phase or callback phase from ajax calls.
>
>
> ajaxErrorHandler
> " If the ajax callback error was timeout...then we alert the user and
> forward to login again. If it was an ajax error callback, then we
> display a modal showing all the available error information. See
> #renderSupportForAjaxErrorHandlerOn: for more details.
> Also... note that in DpQuuveProductionWalkbackErrorHandler >> open: (our
> custom Seaside error handler for GemStone), when there is an AJAX error,
> in the response object we write a JSON serialized dictionary with all
> the error information (see #respondFromAjaxRequestWith:continuation:).
> Therefore, what we must do here is to read the response (will be JSON),
> parse that, and get the useful information. Finally, refresh the
> 'ajaxErrorDialog' with the error info we got and finally show the dialog.
> "
>
> ^ ' if (jqxhr.status == 403) {
> alert("For security reasons we sign people out during
> periods of inactivity. Please sign in again.");
> window.location.href =
> settings.url.split("?")[0].replace("help","");
> } else {
>
> // This is on purpose because sometimes with TinyMCE we would get status
> 0 and empty error...when there was no error
> // The reason is explained in:
> http://bartwullems.blogspot.com.ar/2012/02/ajax-request-returns-status-0.html
> if (jqxhr.readyState == 0 || jqxhr.status == 0) {
> return; //Skip this error
> };
>
> // Lets write to console all error info possbile
> var requestResponse = {
> url: settings.url,
> method: settings.type,
> data: settings.data,
> httpStatus: jqxhr.status,
> error: exception || jqxhr.statusText,
> data: settings.data
> };
>
> responseText = jqxhr.responseText;
> responseText.replace(/[\\"'']/g, ''\\$&'').replace(/\u0000/g, ''\\0'');
> jsonValue = jQuery.parseJSON(responseText);
> console.error(jsonValue);
>
> $(''#ajaxErrorDialog'').find(''.errorTitle'').html(''<span
> style="color:#4F2817;">''+jsonValue.errorTitle+''</span>'');
> $(''#ajaxErrorDialog'').find(''.exceptionDescription'').html(''<span
> style="color:#4F2817;">''+jsonValue.exceptionDescription+''</span>'');
> $(''#ajaxErrorDialog'').find(''.dateAndTime'').html(''<span
> style="color:#4F2817;">''+jsonValue.dateAndTime+''</span>'');
> $(''#ajaxErrorDialog'').find(''.continuationOop'').html(''<span
> style="color:#4F2817;">''+jsonValue.continuationOop+''</span>'');
> $(''#ajaxErrorDialog'').find(''.packagesVersions'').html(''<span
> style="color:#4F2817;">''+jsonValue.packagesVersions+''</span>'');
> $(''#ajaxErrorDialog'').find(''.sitePrefix'').html(''<span
> style="color:#4F2817;">''+jsonValue.sitePrefix+''</span>'');
> $(''#ajaxErrorDialog'').find(''.user'').html(''<span
> style="color:#4F2817;">''+jsonValue.user+''</span>'');
> $(''#ajaxErrorDialog'').find(''.gemPid'').html(''<span
> style="color:#4F2817;">''+jsonValue.gemPid+''</span>'');
> $(''#ajaxErrorDialog'').find(''.gemSessionID'').html(''<span
> style="color:#4F2817;">''+jsonValue.gemSessionID+''</span>'');
>
> $(''#ajaxErrorDialog'').modal(''show'');
>
> }'
>
>
>
> And then, I also render my "ajaxErrorDialog" which is the
> component/dialog rendered when there is an ajax error:
>
>
> renderSupportForAjaxErrorHandlerOn: html
> html tbsModal
> id: 'ajaxErrorDialog';
> with: [
> html
> tbsModalDialog: [
> html
> tbsModalContent: [
> html
> tbsModalHeader: [
> html tbsModalTitle
> level: 4;
> with: [
> html tbsAlert beDanger
> with: [
> html tbsGlyphIcon iconTime.
> html space.
> html text: 'Unexpected Error!'.
> html span
> style: 'text-color: white';
> with: [ html tbsModalCloseIcon ] ] ] ].
> html
> tbsModalBody: [
> "This is a template div that is filled/replaced
> with the real text from DpQuuve >> ajaxErrorHandler"
> html
> text:
> 'The operation you tried failed because of an
> unexpected error. You may want to either try again, sign out and sign in
> and try again, or contact us about the error. However, note that other
> aspects of the program should continue to work normally.'.
> html
> break;
> break.
> html div
> with: [
> html text: 'Error description: '.
> html span class: 'exceptionDescription' ].
> html break.
> html div
> with: [
> html text: 'Error ID: '.
> html span class: 'continuationOop' ].
> html break.
> html div
> with: [
> html text: 'Generated at: '.
> html span class: 'dateAndTime' ].
> html break.
> html div
> with: [
> html text: 'By user: '.
> html span class: 'user' ].
> html break.
> html div
> with: [
> html text: 'Site url: '.
> html span class: 'sitePrefix' ].
> html break.
> html div
> with: [
> html text: 'Packages: '.
> html span class: 'packagesVersions' ].
> html break.
> html div
> with: [
> html text: 'Gem PID: '.
> html span class: 'gemPid' ].
> html break.
> html div
> with: [
> html text: 'Gem Session ID: '.
> html span class: 'gemSessionID' ].
>
> ]"html tbsModalFooter: [
> html tbsButton: 'Close'.
> html tbsButton bePrimary; with: 'Save changes'
> ]" ] ] ]
>
>
> Hope this helps. Let me know if it is clear. If it is not yet, I can do
> (and I should do!) a blog post explaining better.
>
> Cheers,
>
>
> --
> Mariano
> http://marianopeck.wordpress.com
>
>
> _______________________________________________
> seaside mailing list
> [email protected]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
Hi!
Thanks a lot for this sample :)
I will probably take a look in the next weeks (I don't have the time
now) to use that in Synectique Tools.
If I have any problem when I will come back to this issue I will come
back on the subject. I think it will improve a lot Synectique Tools and
my projects! :)
--
Cyril Ferlicot
http://www.synectique.eu
2 rue Jacques Prévert 01,
59650 Villeneuve d'ascq France
_______________________________________________
seaside mailing list
[email protected]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
signature.asc
(application/pgp-signature, 819 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJX5qGwAAoJEBzpUtxBqUIDzQ8P/0EMUb5zr1u/cC6ttAwORfIG TrRihl6s8GVxSccYULWRG7x7Un5UXYYnvd3WPbTWWe28Gp6NhqPhFF7C+83Megyl izqypuHY8Q6oqx7mPTstIcRoGZnGWBAr2+U2axG6MD9Yc4YoX2D2HIFIb3AOK6RK L1eFp6KQOX3PkdaxS+KRiOQAWiwRpWaP0dZYgabbCiIKIXdloIqGUFI0I4PGZJ1T d8qg+81RCjJ1ii1fak6FgfDyvP9U/cGCX5l2tOtdDLzb5cvJz59XVeyqtMorqDVK XSO/jMr/OV2XwJjmlfWEInm9Qk2CAR5rsMhw0dLtSijT7oiMQChS1MKsWxmzWkxy l8ezmE1K30mMlpzw5nRzNwVyv7ilxj//PayKUtB5tETL9Fk0t1HWFOpEtNuvJbwi 05jnhAxvGR6n/HUpsdJoxBHzVx5LzdwSjZNKsyWo5OYrINuOUISrQfp2N9XSFnZN Mm1SJy0QMhxIwT/T+TYfVek+j0pLqtN/m6dlqvxe6OmaQe3pK9Foj7w4wKfSLVWB CXVZM8oJZxOffMKc6c5a/26Tt9ujKIL7ByWN46extVuA9iXAvla+P1lfjmlI7Nln BhETiOjemoZbp6puz0bkOgZXwN3v6IUXSYeB2hBlQUPlNNMRqYvnCsKnmEi6RlOx E1agFu5Ut7ZlG/BnyuyC =IDk1 -----END PGP SIGNATURE-----