Announcement

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

    DSResponse.getErrors() returns map of maps sometimes and map of lists other times

    How are you supposed to parse the object returned by DSResponse.getErrors()? It appears in some responses as a Map<String,Map<String,String>> and in other responses as a Map<String,List<String>>.

    Is there some helper code to convert it into a consistent object? Although the documentation is not clear on this point (in the JS example it appears to be a map of String,String), I would have thought it would be a Map<String,List<String>> where the String is field name and the List<String> is the list of error messages for that field.

    I need to take the errors in a DSResponse and show them in a warning popup. This code seems to handle both cases I've encountered so far but there must be an easier way.
    Code:
    Map<String,Object> errors = response.getErrors();
    StringBuilder sb = new StringBuilder();
    for (Object error : errors.values()) {
    	if (error instanceof List) {
    		sb.append("Errors (list)");
    		for (Map<String, String> errorMap : (List<Map<String,String>>)error) {
    			for (String errorMessage : errorMap.values()) {
    			sb.append("</br>");
    			sb.append(errorMessage);
    			}
    		}
    	}
    	if (error instanceof Map) {
    		sb.append("Errors (map)");
    		for (String errorMessage : ((Map<String,String>)error).values()) {
    			sb.append("</br>");
    			sb.append(errorMessage);
    		}
    	}
    }
    SC.warn(sb.toString(), new BooleanCallback() {
    	@Override
    	public void execute(Boolean value) {
    		grid.startEditing(event.getRowNum(), event.getColNum(), false);
    	}
    });

    #2
    Can you show the response in the RPC tab where you are seeing Map<String,Map<String,String>>? That format shouldn't be coming up in normal operations (it relates to some advanced support for nested structures).

    Comment


      #3
      Here it is. It happens when I do multiple calls to DSResponse.addError("field", "error message") with the same field name, "packCompItemNumber" in this case.
      Code:
      [
          {
              queueStatus:-1, 
              errors:[
                  {
                      packCompItemNumber:[
                          {
                              errorMessage:"Component class must be the same as the prepack item."
                          }, 
                          {
                              errorMessage:"Component style must be the same as the prepack item."
                          }, 
                          {
                              errorMessage:"Component vendor must be the same as the prepack item."
                          }
                      ]
                  }
              ], 
              isDSResponse:true, 
              invalidateCache:false, 
              status:-4, 
              data:null
          }
      ]

      Comment


        #4
        Ah, OK. We have logic to simplify a more expanded error format the server can send in certain cases, but it isn't currently catching this case.

        We'll fix this so that you receive the standard Map<String, List> in this case. If you add logic to handle this format now, it will be harmless in the future.

        Comment


          #5
          I'm still getting the Map<String,Map<String,String>> format using SmartClient Version: SC_SNAPSHOT-2011-01-29/PowerEdition Deployment (built 2011-01-29).

          This is what the request and response look like. In this case I'm using DataSource.addData() to create the request.
          Code:
          {
              "dataSource":"IPITHDR", 
              "operationType":"add", 
              "data":{
                  "ITTO":0, 
                  "ISPQ":0, 
                  "ISPR":0, 
                  "csCompany":"PROF SERVICES 3.X", 
                  "IMLT":1, 
                  "ISBN":"", 
                  "INVC":15, 
                  "IGTIN":"00400000005133", 
                  "COMPQTY":6, 
                  "ISUD":"", 
                  "IUCD":"", 
                  "ICSG":"", 
                  "ILVC":15, 
                  "ISUG":0, 
                  "IDES":"BIAS STRIPE", 
                  "TICKET":"T", 
                  "ISDS":"SHIRTS", 
                  "CLRNAME":"BLACK", 
                  "csNewSKU":"Y", 
                  "IACC":15, 
                  "ITFR":0, 
                  "IGTINTP":"1", 
                  "ITMP":0, 
                  "IVLC":12, 
                  "IVNC":15, 
                  "ILOCF":0, 
                  "IMIN":1, 
                  "ILOCC":"", 
                  "IVST":"MB1234", 
                  "csLibrary":"IPTSFILY", 
                  "ISUQ":1, 
                  "IPKTYPE":"", 
                  "IPLU":32, 
                  "IRET":32, 
                  "IALT":0, 
                  "INCI":null, 
                  "csError":"", 
                  "IORT":0, 
                  "ItemNumber":"8501-08500-0001-002-0002", 
                  "ICLS":8501, 
                  "IVEN":8500, 
                  "ISTY":1, 
                  "ICLR":2, 
                  "ISIZ":2, 
                  "ITKT":"T"
              }, 
              "willHandleError":true, 
              "showPrompt":true, 
              "prompt":"Defining new prepack component items.", 
              "oldValues":{
                  "ITTO":0, 
                  "ISPQ":0, 
                  "ISPR":0, 
                  "csCompany":"PROF SERVICES 3.X", 
                  "IMLT":1, 
                  "ISBN":"", 
                  "INVC":15, 
                  "IGTIN":"00400000005133", 
                  "COMPQTY":6, 
                  "ISUD":"", 
                  "IUCD":"", 
                  "ICSG":"", 
                  "ILVC":15, 
                  "ISUG":0, 
                  "IDES":"BIAS STRIPE", 
                  "TICKET":"T", 
                  "ISDS":"SHIRTS", 
                  "CLRNAME":"BLACK", 
                  "csNewSKU":"Y", 
                  "IACC":15, 
                  "ITFR":0, 
                  "IGTINTP":"1", 
                  "ITMP":0, 
                  "IVLC":12, 
                  "IVNC":15, 
                  "ILOCF":0, 
                  "IMIN":1, 
                  "ILOCC":"", 
                  "IVST":"MB1234", 
                  "csLibrary":"IPTSFILY", 
                  "ISUQ":1, 
                  "IPKTYPE":"", 
                  "IPLU":32, 
                  "IRET":32, 
                  "IALT":0, 
                  "INCI":null, 
                  "csError":"", 
                  "IORT":0, 
                  "ItemNumber":"8501-08500-0001-002-0002", 
                  "ICLS":8501, 
                  "IVEN":8500, 
                  "ISTY":1, 
                  "ICLR":2, 
                  "ISIZ":2, 
                  "ITKT":"T"
              }, 
              "requestId":"IPITHDR$62781"
          }
          
          {
              "operationId":"custom", 
              "transactionNum":60, 
              "httpResponseCode":200, 
              "transport":"xmlHttpRequest", 
              "status":-4, 
              "httpHeaders":{
                  "X-Included-Test2":true, 
                  "X-Included-Test":true, 
                  "Expires":"Wed, 09 Feb 2011 16:33:45 GMT", 
                  "Content-Length":"168", 
                  "Cache-Control":"no-cache", 
                  "Pragma":"no-cache", 
                  "Content-Type":"text/plain; charset=utf-8", 
                  "Content-Encoding":"gzip", 
                  "Server":"Jetty(6.1.x)"
              }, 
              "isStructured":true, 
              "results":{
                  "queueStatus":-1, 
                  "errors":[
                      {
                          "ICLS":{
                              "errorMessage":"Class is not defined."
                          }
                      }
                  ], 
                  "isDSResponse":true, 
                  "invalidateCache":false, 
                  "status":-4, 
                  "data":null
              }, 
              "isDSResponse":true, 
              "invalidateCache":false, 
              "data":null, 
              "startRow":0, 
              "endRow":0, 
              "totalRows":0
          }
          My DMI code is just doing this.
          Code:
          DSResponse resp = new DSResponse();
          resp.setStatus(DSResponse.STATUS_VALIDATION_ERROR);
          resp.addError("ICLS", "Class is not defined.");
          return resp;

          Comment


            #6
            We've now made a change to how DSResponse.getErrors() behaves in both 3.1p and 4.0d which should fix this. You should now get back a map of string (fieldName) to array of string (error messages).

            This change will be present in nightly builds dated March 5 and above

            Regards
            Isomorphic Software

            Comment

            Working...
            X