question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Catching Backend errors

See original GitHub issue

Is your feature request related to a problem? Please describe. Not being able to get hands on the error response provided by backend

Describe the solution you’d like Basically, I go along these lines

myExtOdataV2service.entityset.reauestbuilder(). ... .execute(destination) 

and the request is sent correctly to the source system, which returns a (perfectly valid) error response as odata v2 json, which I need to grab and pass along. Adding a catch() at the end of the above statement, I get an error object, containing the original json somewhere in the middle of the stacktrace string… Sure, I could go and try to find it using regex or something, but is there a “proper” way to catch the original backend error in @sap-cloud-sdk?

Describe alternatives you’ve considered Sure, I could go and try to find it using regex in the stacktrace.

Additional context example stacktrace inside the catch

Create request failed!
    at Object.errorWithCause (XXX/srv/node_modules/@sap-cloud-sdk/util/dist/error.js:5:20)
    at XXX/srv/node_modules/@sap-cloud-sdk/core/dist/odata/v2/request-builder/create-request-builder.js:124:54
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at ...
Caused by:
Error: post request to https://*****_SRV failed! Personnel Number ******** : Incorrect data in ***
{"code":"***/***","message":{"lang":"en","value":"Personnel Number ******** : Incorrect data in ***"},"innererror":{"application":{"component_id":"","service_namespace":"/***/","service_id":"***","service_version":"0001"},"transactionid":"***","timestamp":"20201027150920.7447650","Error_Resolution":{"SAP_Transaction":"For backend administrators: run transaction /IWFND/ERROR_LOG on SAP Gateway hub system and search for entries with the timestamp above for more details","SAP_Note":"See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"},"errordetails":[{"code":"***/***","message":"Personnel Number ******** : Incorrect data in ***","longtext_url":"/sap/opu/odata/iwbep/message_text;o=LOCAL/","propertyref":"","severity":"error","target":""}]}}
    at Object.errorWithCause (XXX/srv/node_modules/@sap-cloud-sdk/util/dist/error.js:5:20)
    at constructError (XXX/srv/node_modules/@sap-cloud-sdk/core/dist/odata/common/request/odata-request.js:295:23)
    at XXX/srv/node_modules/@sap-cloud-sdk/core/dist/odata/common/request/odata-request.js:265:51
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at ...
Caused by:
Error: Request failed with status code 400
    at createError (XXX/srv/node_modules/axios/lib/core/createError.js:16:15)
    at settle (XXX/srv/node_modules/axios/lib/core/settle.js:17:12)
    at IncomingMessage.handleStreamEnd (XXX/srv/node_modules/axios/lib/adapters/http.js:236:11)
    at IncomingMessage.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1223:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

Feature implementation sorry for not providing a pull request, here is a quick solution: @sap-cloud-sdk/util/dist/error.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.errorWithCause = void 0;
function errorWithCause(message, cause) {
    var newError = new Error(message);
    // Stack is a non-standard property according to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Custom_Error_Types
    if (newError.stack && cause.stack) {
        newError.stack = newError.stack + '\nCaused by:\n' + cause.stack;
    }
    // INSERT BEGIN -- @the-docta
    if (cause.isAxiosError) {
        // these are the fields set by axios in lib/core/enhanceError (as of 0.19.2)
        newError.isAxiosError = cause.isAxiosError
        newError.config = cause.config;
        newError.request = cause.request;
        newError.response = cause.response;
        if (cause.code) {
            newError.code = cause.code;
        }
    }
    // INSERT END -- @the-docta
    return newError;
}
exports.errorWithCause = errorWithCause;

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
marikanercommented, Nov 6, 2020

Hey @the-docta,

you telling us, that it is high priority for you is already making it higher priority, but it was never really low priority, it is just not being worked at yet (we’re quite a small team). I changed the name in the board to backlog to avoid future confusion. 😉 We are planning on discussing possible solutions next week. Once we have decided on an approach I will link the the ADR for this here, it would be great to hear your feedback on it then.

After that it can be implemented. This can be either done by us, or if you are willing to contribute of course you are also welcome to do so. In any case, I’ll keep you posted.

0reactions
marikanercommented, Dec 28, 2020

Released in version 1.34.0. Feel free to open a new issue in case you have further requirements.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error Handling from Backends to the Frontend - The New Stack
Input errors: This happens if validation is missing in the frontend but gets caught or thrown by the backend. Could be input validation...
Read more >
Best Practices for Node.js Error-handling - Toptal
Using Node.js built-in Error object is a good practice because it includes intuitive and clear information about errors like StackTrace, which most developers ......
Read more >
Track Backend Errors - Datadog Docs
Learn how to track backend errors from your logs.
Read more >
Handling back-end errors - Forums - IBM Support
Hi,. Have a case where an error handling action has been added to the request/response processing to allow customisation of error responses to...
Read more >
Node.js Error Handling Best Practices - Sematext
Learn what is Node.js error handling and why do you need it. From using middleware to catching uncaught exceptions, discover the best ways ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found