[Seaside] Ajax and error management
philippe.marschall at gmail.com
Sun May 15 12:10:02 UTC 2011
2011/5/14 Johan Brichau <johan at inceptive.be>:
> Exceptions in Seaside are handled by an instance of (a subclass of) WAExceptionHandler. Setting the exception handler is part of the application configuration.
> For development, Seaside provides you with exception handlers (e.g. WAWalkbackErrorHandler) that return an exception page and that can open a debugger on the server-side (or they put a continuation on the objectlog in GLASS).
> Some examples:
> - http://stackoverflow.com/questions/377644/jquery-ajax-error-handling-show-custom-exception-messages
> - http://api.jquery.com/ajaxError/
> To change the server-side behavior. I think you can find your way by looking at the implementation of the existing handlers.
> To give you yet another example, here is the principal code of an error handler we are using in production code. In combination with a global ajax error handler, it makes sure that a decent error message is put on the screen (in a kind of dialog window) whenever an error occurred server-side in an ajax callback.
> handleDefault: anException
> [self logErrorToDisk: anException]
> ensure: [self requestContext respond: [ :response |
> contentType: WAMimeType textHtml;
> nextPutAll: (self rendererClass builder
> fullDocument: true;
> rootBlock: [ :root | root title: anException description ];
> render: [:html | html render:(NPProductionErrorDialog exception: anException)])]]
> Hope this gets you on your way!
Nice summary. Note that there is WARequest >> #isXmlHttpRequest that
allows you to write special error handling code for AJAX. If you want
to handle the error on the client side you need to set the HTTP status
code (WARespnse >> #status:) to some server error (5xx). Note that
error handling code. Either by redirecting to it with window.location
or by just simply changing the DOM.
More information about the seaside