Error handling
Turning a failure into a response a client can act on — protocol-correct error payloads, correlation, and a boundary between internal detail and what a caller sees.
Overview
@sap/cds Provides req.error and req.reject, and serialises the result into protocol-correct payloads with target paths.
com.sap.cds:cds-services-bom Ships ServiceException for aborting an event with a mapped HTTP status and the Messages API for collecting errors, warnings, info and success messages on a request without aborting it, both usable without an extra dependency.
Not covered: It stops at the response the client receives. On Node.js in production a 5xx error goes out as its generic message only, and capire's advice for an unexpected error is to make sure it is logged and not to keep the app running; keeping a record of failures beyond a loggingLoggingSeeing what a running service did, in a form something can read afterwards — levels, a formatter that suits a laptop and one that suits a log service.SAP only line and telling a person about them, which is notificationsNotificationsTelling a person something happened when they are not looking at the screen — a notification in the launchpad, an email, a message somewhere they already are.SAP and community, narrow by design, are left to a plugin or the application's own code.
In ABAP the question is how a failure travels back to the caller: as a class-based exception, as a returned result object that carries the error, or as a message table such as BAPIRET2.
Class-based exceptions: an exception is an instance of an exception class, raised with RAISE EXCEPTION or THROW in a conditional expression, and handled in the CATCH blocks of a TRY structure.
Not covered: At raising and catching. The language has no result value for an expected failure, and converting exception texts into BAPIRET2 or SYMSG for a caller is left to the application.
Libraries that return a failure as a value, such as RESULT-for-ABAPRESULT-for-ABAPAn ABAP implementation of the result pattern: a method returns an object built with ok or fail instead of raising an exception for an expected failure, and several results combine into one.independent, abap, and that convert exception texts into BAPIRET2 and SYMSG, such as sap-usi-exceptionsap-usi-exceptionA shared root exception class and text getter API used across SchwarzIT's USI ABAP developments, converting an exception's text into a common format such as BAPIRET2 or SYMSG.independent, abap. ABAP-PRCABAP-PRCA framework for custom multi-step ABAP processes: a process class declares the states, and the framework runs each document through them and monitors the run.independent, abap is a process framework that collects errors as messages and resumes a failed object on the step that failed.
Artifacts
Content
Show 13 more
Seen working
Details
Coverage
For your agent
- Ref
capability:error-handling- JSON
- /capabilities/error-handling.json
- MCP
- Connecting an agent