Announcement

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

    STATUS_FAILURE and error message

    Hi,
    I've just found a problem with my application that probably appear some time ago (I assume that after upgrade to SmartGWT 2.4).
    From the start.
    I'm using modified RestDataSource with my own transformResponse() method. That's because I've got only PHP on server side.
    I was using this method to show a special error that not concern specific fields. I was just showing an error message by SC.warn() and setting status as:
    Code:
    response.setStatus(RPCResponse.STATUS_FAILURE);
    Unfortunately it doesn't work any more and another dialog appears with:
    Code:
    Server returned FAILURE with no error message.
    I've tried to add errors information on server side or even on client side with:
    Code:
    JSONArray errors = XMLTools.selectObjects(jsonData, "/response/errors");
    response.setErrors(errors.getJavaScriptObject());
    In JSON response errors were set correctly.

    My question is how to set this error message when setErrors() doesn't work in this case. I've tried also other RPC statuses with same results.

    I cannot find docs about purpose and expected behaviour with each of this statuses. Maybe you can direct me to this.

    Maybe problem is in other place. From start I call from code:
    Code:
    listGrid.addData(record, , new DSCallback() {...}) ;
    So in fact there is no form that could show an error. Maybe here is a problem.

    Thanks for any help.

    #2
    I think I've found a temporary solution to my problem.
    If I set status using incorrect integer value, for example 100 the error message does not show and it appears that further operations by datasource are not performed.
    Is it the right approach to override default behaviour in special cases?

    But question about how to correctly set error message remains?
    Maybe I need to set a special attribute to DSResponse that does not have get/set methods yet.

    Thanks for any advice

    Comment


      #3
      Hi,
      I had the exact same problem, but I think I found a more elegant solution. Instead of setting status to 100, I specified
      Code:
      willHandleError:true
      on my RPCRequest object.
      For example:
      Code:
      response.setStatus(RPCResponse.STATUS_FAILURE);
      request.setWillHandleError(true);
      Hope this helps!

      Comment


        #4
        Hi,

        In my case your solution doesn't solve my whole problem.
        When error appears during FETCH operation message is shown correctly but DataSource or ListGrid tries to fetch data another time.
        That causes infinite shows of error, so the application is unusable until refresh of the browser.

        When I set status to 100 error show only ones and application can be used further (of course besides of this ListGrid).

        Best regards

        Mariusz Goch

        Comment


          #5
          Hi Mariusz,
          You're right. My solution works for ADD, UPDATE and DELETE, but doesn't work for FETCH. It appears that FETCH operations can't have validation errors (see http://forums.smartclient.com/showthread.php?t=16265&page=2).
          For FETCH operations, when an error occurs, I show the error message to the user, set the status to success and the data to an empty list. Here's my code:
          Code:
          SC.warn(errorMessage)
          p_response.setStatus(RPCResponse.STATUS_SUCCESS);
          p_response.setData(new Record[0]);
          this.processResponse(p_requestId, p_response);
          Regards,

          Comment


            #6
            Hi,

            Your solution looks all right and make sense but for some reason I cannot make this work.
            Where you put this code?
            I've tried something like this:
            Code:
            protected void transformResponse(DSResponse response, DSRequest request, Object jsonData) {
            	try {
            		JSONObject jsonResponse = XMLTools.selectObjects(jsonData, "/response").get(0).isObject();
            		int status = (int) jsonResponse.get("status").isNumber().doubleValue();
            		if(status == -1) {
            			request.setWillHandleError(true);
            			if(request.getOperationType() == DSOperationType.FETCH) {
            				response.setStatus(RPCResponse.STATUS_SUCCESS);
            				response.setData(new Record[0]);
            				this.processResponse(request.getRequestId(), response);
            			}
            			SC.warn(jsonResponse.get("data").isString().stringValue());
            		}
            	} catch (RuntimeException e) {
            		response.setStatus(RPCResponse.STATUS_FAILURE);
            		SC.warn("Connection error");
            	}
            }
            Best regards,
            Mariusz Goch

            Comment


              #7
              Hi,
              My code is in transformRequest instead of transformResponse, but I don't know why your code doesn't work, looks fine for me.
              Regards,

              Comment


                #8
                Mariusz,
                I found it in little one sentence in documentation of RPCManager:
                Code:
                public static void setHandleErrorCallback(HandleErrorCallback callback)
                
                    By default handleError() always logs a warning. In addition, if response.data was set to a String, a warning dialog will be shown to the user with response.data as the message, which allows the server to send user error messages back without writing custom client-side error handling.
                so.. to show Warn Window with custom message just on Your server put message into "data" attribute or like me in transformResponse:
                Code:
                            GWT.log(e.getMessage());
                            response.setStatus(RPCResponse.STATUS_FAILURE);
                            response.setAttribute("data", e.getMessage());
                Nearly 9 hours wasted to find this how to change "Server returned FAILURE with no error message." to custom message.

                Regards
                Wojciech Bartosiak

                -----
                Pozdrawiam Polaków na całym świecie :)

                Comment


                  #9
                  I managed to prevent a default warning message with event.cancel();

                  Code:
                   new HandleErrorHandler(){ 
                  	@Override
                  	public void onHandleError(ErrorEvent event) {
                  		customHandleError(event);
                  		event.cancel();
                  	}
                  }

                  Comment

                  Working...
                  X