How does REST API return errors from error-string of dataset
 
Forums / SmartComponent Library - Developer Forum / How does REST API return errors from error-string of dataset

How does REST API return errors from error-string of dataset

9 posts, 0 answered
  1. Toni Perätalo
    Toni Perätalo avatar
    5 posts
    Registered:
    08 Feb 2019
    08 May 2019
    Link to this post
    Hi,
    Validation etc errors are stored in error-string of dataset. JSDO API shows those in response like this:

    prods:before: { },
    prods:errors: 
    {
    eSalesOrder: 
    [
    {
    prods:id: "eSalesOrder145664",
    prods:error: "Sales type is mandatorySlsTypeeSalesOrderPayment term is mandatoryPaytermeSalesOrder"
    }
    ],
    eSalesLine: 
    [
    {
    prods:id: "eSalesLine149760",
    prods:error: "Stock is mandatoryStockeSalesLine"
    },
    {
    prods:id: "eSalesLine149761",
    prods:error: "Given value P100 in field Itemcode is invalidItemCodeeSalesLineStock is mandatoryStockeSalesLine"
    },
    {
    prods:id: "eSalesLine149762",
    prods:error: "Given value in field 'Location' = 'Foo' unknown or invalid. Saving record failed.Stock is mandatoryStockeSalesLine"
    }
    ]
    }


    How does REST API return these? For some reason I cannot get my REST API working (but that's another issue), so I would appreciate a lot, if you could provide an example how the REST response would look like with those errors. 

    Cheers,
    Toni






  2. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    08 May 2019 in reply to Toni Perätalo
    Link to this post
    HI Ton,

    not sure what you're asking here. We're using the standard WRITE-JSON method of the ProDataset and the JSDO works fine with that. You are seeing the errors returned in your JSON. So that's working. 

    Do you want to know how to handle them from the JSDO?
  3. Toni Perätalo
    Toni Perätalo avatar
    5 posts
    Registered:
    08 Feb 2019
    10 May 2019
    Link to this post
    Hi,

    I was curious to know how the http response payload (json) looks like, when a I try to create a record with business entity using REST interface and it fails for validation error. Especially how those errors are shown. I'll try to explain more detailed.

    I try to create a sales order record using REST (using http client like Postman, not our real "frontend". For just an example):
    POST server/web/salesorders
    (this uses SalesOrderBusinessEntity).
    There are some validations done using Validate class of SmartComponentLibrary. When validation fails, those routines in Validation class set the error flag of dataset true and also set error-string of dataset buffer.
    Now the backend returns the response to frontend. 

    I'd like to know how the http response payload looks like in this case. Especially how those error messages from error-string of dataset buffer are shown in response payload in case of REST call.

    If I would have used JSDO call (POST server/web/Foo.Sales.SalesOrderBusinessEntity etc.) the response looks like:
    {
        "dsSalesOrder": {
            "prods:hasChanges": true,
            "eSalesOrder": [
                {
                    "prods:id": "eSalesOrder205056",
                    "prods:rowState": "created",
                    "prods:hasErrors": true,
                    "OrderNum": 0,
                    "OrdCustNum": 1,
                    "OrdAddrNum": 0,
                    "PayTerm": "",
                    "DlvCustNum": 0,
                    "DlvAddrNum": 0,
                    "InvCustNum": 0,
                    "InvAddrNum": 0,
                    "DlvTerm": "",
                    "TraMode": "",
                    "Currency": "",
                    "SlsType": "",
                    "OrderDate": null               
                }
            ],
            "prods:before": {},
            "prods:errors": {
                "eSalesOrder": [
                    {
                        "prods:id": "eSalesOrder205056",
                        "prods:error": "Sales Type must be given (SlsType)\u0004SlsType\u0004eSalesOrder\u0003Payment term must be given (PayTerm)\u0004PayTerm\u0004eSalesOrder\u0003This is error that cannot be targetted to specific field"
                    }
                ]
            }
        }
    }

    But how the response payload looks like if I'd have used REST call to create a record? Reason why I'm asking is that we have something wrong with our REST setup and I cannot test right know it by myself.

    Hope that make the question more clear.

    Toni









    Last modified on 10 May 2019 04:05 by Toni Perätalo
  4. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    10 May 2019 in reply to Toni Perätalo
    Link to this post
    This is for the JSDO Interface? Not RESTful? 

    We're using the ProDataset's WRITE-JSON method to return the ProDataset. As you can see in your sample response, that extracts the prods_before structure for the before-image and the prods:errors for the error information. This is the content of the ERROR-STRING attribute of the records.

    The JSDO has been implemented to understand this structure. 
  5. Toni Perätalo
    Toni Perätalo avatar
    5 posts
    Registered:
    08 Feb 2019
    24 May 2019 in reply to Mike Fechner
    Link to this post
    Mike Fechner said:This is for the JSDO Interface? Not RESTful? 

    Yes, the example was from JSDO interface. But I was curious, how the same would look in RESTful interface.


    We're using the ProDataset's WRITE-JSON method to return the ProDataset.

    Is it same for RESTful?

    This is the content of the ERROR-STRING attribute of the records.

    Yes, I know this. Question was, how this is returned in case of RESTful interface?

    btw. I tried that WRITE-JSON for a dataset containing ERROR-STRING, but did not get the errors to json. Is there some option to be set to get dataset errors to json?

    Last modified on 24 May 2019 06:05 by Toni Perätalo
  6. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    24 May 2019 in reply to Toni Perätalo
    Link to this post
    No, RESTful uses a different semantic - to comply with general recommendations for RESTful.

    With RESTful, validation errors are returned as a JSON object detailling the error message (validation message) and http status in the 4xx or 5xx range (not sure right now).

    This allows JavaScript developers doing an http post to use the promise.fail branch to handle validation errors.
  7. Toni Perätalo
    Toni Perätalo avatar
    5 posts
    Registered:
    08 Feb 2019
    24 May 2019 in reply to Mike Fechner
    Link to this post
    OK, thanks. Now we are on a same map :) So, is there any change you could provide an example of that  response? No hurry. (For some reason our RESTful interface is not working anymore, but I don't have time to find out why).
  8. Mike Fechner
    Mike Fechner avatar
    319 posts
    Registered:
    14 Sep 2016
    24 May 2019 in reply to Toni Perätalo
    Link to this post
    I suggest you log an support ticket, so that we can help investigating that issue first ...
  9. Toni Perätalo
    Toni Perätalo avatar
    5 posts
    Registered:
    08 Feb 2019
    27 May 2019 in reply to Mike Fechner
    Link to this post
    OK. I will look it once again and if I still cannot get it working, I will log a ticket for that.

    Cheers!
9 posts, 0 answered