Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Alert text in default error handler is HTML escaped

    I am currently using latest evaluation release of SmartClient (v11.0p_2016-04-12) and I'm evaluating it in order to reengineer a large ERP application.
    I've found a little nuisance in the way error messages are displayed by the default error handler.
    It seems that error text displayed is HTML escaped and produces an output like this:

    Click image for larger version

Name:	Schermata del 2016-04-27 16-00-18.png
Views:	84
Size:	14.4 KB
ID:	237442

    the response returned, as displayed by Chrome Developer Tools is:

    //isc_RPCResponseStart-->[{affectedRows:0,errors:[{"null":{errorMessage:"cf: E' stato violato il seguente constraint: ARTI_UM_CF"}}],invalidateCache:false,isDSResponse:true,operationType:"remove",queueStatus:-1,status:-4,data:null}]//isc_RPCResponseEnd

    is it possibile to avoid this escape?

    Thank you.

    #2
    There are a couple of problems here:
    1. the errors coming from your server are corrupt - errors are being reported against a field called "null" and it looks like you've got an extra Array wrapped around the errors somehow. It's not clear how this could happen - it would seem to require using internal, undocumented APIs in your server code.

    2. You generally shouldn't be allowing validation errors to go to the general error handler, since even with a correctly formatted error, there's no gold way for the central error handling logic to display such errors. The central error handler doesn't even have the context to display the user-visible titles for fields rather than the internal field names (which the user wouldn't recognize). Framework components will always set rpcRequest.willHandleError:true to avoid central error handling being used, and then display the errors in some useful way.

    Comment


      #3
      Thank you for your quick answer.
      About 1, this does not surprise me since I'm implementing a custom DataSource that works with our ERP ORM which I wrote fifteen years ago. I can't replace it since most of the business logic of the whole system depends on its API. Actually I added an error message to the DSResponse (using addError) with a field value of null since some messages do not map to a particular field. I see from the response that the list of messages is marshalled as a JSON object (map) so I understand your concern. What value should I provide for fieldName if there is no field to attach the error to? (in this case this is a constraint violation at the database layer during a DELETE operation). I don't know why an additional array wraps the error. I'm just using the DSResponse public API (here res is the DSResponse object):

      for (ApplicationError e : sess.getErrors()) {
      if (e.hasFields()) {
      for (String field : e.getFields()) {
      res.addError(field, e.getLocalizedMessage());
      }
      } else
      res.addError(null, e.getLocalizedMessage());
      }
      I probably need to replace the null with something else.

      Now, about your point 2, I wouldn not like to implement error handling for each component and would prefer having a generic client side error handler. I know it is possible to do this from the documentation which, by the way, is excellent (I'm new to SmartClient, I've been using it only for a few days, and I'm a fast learner). I can override RPCManager.handleError() and/or RPCManager.handleTransportError(). Are there any examples you can point me to that I can use as a starter for my implementation? I'd also like to distinguish between Errors, Warnings (that do not cause the tx to fail) and informational messages, and need to handle server side generated confirmation requests like it happens in my current framework.

      Thank you very much for your support.

      Comment


        #4
        Read the Error Handling overview - it covers all of your questions.

        Comment

        Working...
        X