Skip to Content
0
Aug 07, 2023 at 03:59 PM

CAP on Node.js OData v2 $batch collecting req.errors issue - only one of requests returns errors

273 Views Last edit Aug 07, 2023 at 04:19 PM 3 rev

Hi colleagues,

I have an OData v2 service based on Node.js CAP.

The service receives queries in a batch format.

--batch_df3d-e5a9-254b
Content-Type: multipart/mixed; boundary=changeset_0359-ad5d-07cc

--changeset_0359-ad5d-07cc
Content-Type: application/http
Content-Transfer-Encoding: binary

MERGE POItems_QuantityChange(purchaseOrder='4500000002',purchaseOrderLine='00010') HTTP/1.1
X-Requested-With: XMLHttpRequest
Prefer: handling=strict
sap-contextid-accept: header
Accept: application/json
Accept-Language: en
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
Content-Type: application/json
Content-ID: id-1691421850671-932
Content-Length: 258

{"newQuantity":"1111","__metadata":{"type":"CreateRequests.POItems_QuantityChange","uri":"https://port4004-workspaces-ws-ghq2b.eu10.applicationstudio.cloud.sap/v2/create-requests/POItems_QuantityChange(purchaseOrder='4500000002',purchaseOrderLine='00010')"}}
--changeset_0359-ad5d-07cc
Content-Type: application/http
Content-Transfer-Encoding: binary

MERGE POItems_QuantityChange(purchaseOrder='4500000002',purchaseOrderLine='00011') HTTP/1.1
X-Requested-With: XMLHttpRequest
Prefer: handling=strict
sap-contextid-accept: header
Accept: application/json
Accept-Language: en
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
Content-Type: application/json
Content-ID: id-1691421850671-934
Content-Length: 258

{"newQuantity":"1111","__metadata":{"type":"CreateRequests.POItems_QuantityChange","uri":"https://port4004-workspaces-ws-ghq2b.eu10.applicationstudio.cloud.sap/v2/create-requests/POItems_QuantityChange(purchaseOrder='4500000002',purchaseOrderLine='00011')"}}
--changeset_0359-ad5d-07cc
Content-Type: application/http
Content-Transfer-Encoding: binary

MERGE POItems_QuantityChange(purchaseOrder='4500000002',purchaseOrderLine='00012') HTTP/1.1
X-Requested-With: XMLHttpRequest
Prefer: handling=strict
sap-contextid-accept: header
Accept: application/json
Accept-Language: en
DataServiceVersion: 2.0
MaxDataServiceVersion: 2.0
Content-Type: application/json
Content-ID: id-1691421850671-936
Content-Length: 258

{"newQuantity":"1111","__metadata":{"type":"CreateRequests.POItems_QuantityChange","uri":"https://port4004-workspaces-ws-ghq2b.eu10.applicationstudio.cloud.sap/v2/create-requests/POItems_QuantityChange(purchaseOrder='4500000002',purchaseOrderLine='00012')"}}
--changeset_0359-ad5d-07cc--

--batch_df3d-e5a9-254b--<br>

What I need is to be able to receive multiple errors from several requests of the batch. In the update handler I'm currently raising it in a next way:

    const creationRequestErrors = await this.applyCreationRequestValidations(itemForRequest, newQuantity, requestReasonId, comment, req);

    if (creationRequestErrors.length) {
      
      creationRequestErrors.forEach((e) => req.error({
        code: httpCodes.badRequest,
        message: e.longMessage + itemForRequest.purchaseOrderLine,
        target: 'newQuantity',
        status: httpCodes.badRequest,
      }));

      return;
    }<br>

When there's more then one error in a single request - everything is fine. I receive "Multiple errors occurred" with details of each one.

Although when errors appear in multiple requests of the $batch - the response contains only errors from one of the requests of $batch (not necessarily first one).

--batch_df3d-e5a9-254b
content-type: application/http
content-transfer-encoding: binary
content-id: id-1691421850671-936

HTTP/1.1 400 Bad Request
content-type: application/json
dataserviceversion: 2.0
content-length: 359

{"error":{"code":"400","message":{"lang":"en","value":"Request Reason is required.00012"},"target":"newQuantity","severity":"error","ContentID":"id-1691421850671-936","innererror":{"errordetails":[{"code":"400","message":{"lang":"en","value":"Request Reason is required.00012"},"target":"newQuantity","severity":"error","ContentID":"id-1691421850671-936"}]}}}
--batch_df3d-e5a9-254b--

My OData v2 setup

cds.on('bootstrap', (app) => {
    app.use(cov2ap({
        propagateMessageToDetails: true,
        continueOnError: true
    }));
});

My Node.js env packages are

cds -v
@sap/cds: 6.8.4
@sap/cds-compiler: 3.9.4
@sap/cds-dk: 7.0.2
@sap/cds-dk (global): 6.8.1
@sap/cds-foss: 4.0.2
@sap/cds-mtx: -- missing --
@sap/cds-odata-v2-adapter-proxy: 1.9.21
@sap/eslint-plugin-cds: 2.6.3
@sap/textbundle: 4.2.0
@sap/xssec: 3.2.18
Node.js: v16.19.0

Can it be fixed? Or is there any workarounds?

Thank you in advance.