OData Gateway Part 9: Error Handling and the Message Container
Preview · a free account unlocks the full lesson
Return meaningful errors from Gateway services: business vs technical exceptions and their HTTP status codes, the message container for BAPI and T100 messages, leading messages and error details, success and warning messages in the sap-message header, and what Fiori shows to the user.
In this lessonShow sectionsHide sections
Visual overview
Explanation
Part 8 covered changing data; now errors need to reach the user clearly. /IWBEP/CX_MGW_BUSI_EXCEPTION represents a business error the user can actually fix, defaulting to HTTP 400, while /IWBEP/CX_MGW_TECH_EXCEPTION represents a technical failure, defaulting to HTTP 500.
Business exceptions cover things like a failed validation, a locked record, a record not found (using textid resource_not_found, which maps to 404), or missing authorization, while technical exceptions cover unexpected states, RFC failures, and programming errors; either can take an optional http_status_code parameter to set something more specific, such as 409 for conflict or 403 for forbidden.
The message container, obtained via mo_context->get_message_container( ), collects messages from T100 or BAPI sources: add_messages_from_bapi( it_bapi_messages = lt_return ... ) takes all the BAPIRET2 lines, add_message( iv_msg_type, iv_msg_id, iv_msg_number, iv_msg_v1 ... ) adds a specific T100 message, and add_message_text_only( iv_msg_type = 'E' iv_msg_text = ... ) adds free text. Raising the exception together with this message container returns the messages as error details in the response; the first or most important error becomes the leading message, with the rest going into innererror/errordetails.
Create a free account to keep reading
You have read the opening of this lesson. A free ERPClimb account unlocks the rest of it, every other lesson and topic, and your learning history, so you can pick up exactly where you stopped. No card needed.
- Full explanation
- Code example
- Real project scenario
- Common mistakes
- Best practices
- Interview angle
One tap with Google works too. Every topic keeps its first lesson open to everyone.
Keep exploring
Interview questions on this topic
Referenced SAP objects
Reviewed reference pages for the objects this page mentions.
Check before use: lesson examples are educational, not a guarantee of correctness for your SAP edition or release. Sample code has not been executed on your SAP system. Confirm API availability, syntax, authorizations and business impact in an approved development or test environment.