odatasapui5abapsap-gateway

Can i change in the OData errorhandling the errordetails property?


is there a way to change in the /IWBEP/CX_MGW_BUSI_EXCEPTION the errordetails the property code? Like write my own stuff in there

For Example

enter image description here


Solution

  • Raise /iwbep/cx_mgw_busi_exception with custom message

        DATA lr_busi_exception TYPE REF TO /iwbep/cx_mgw_busi_exception.
        DATA lr_mcontainer TYPE REF TO /iwbep/if_message_container.
    
        DATA lv_message_text TYPE bapi_msg.
        DATA lv_message_attr1 TYPE symsgv.
        DATA lv_message_attr2 TYPE symsgv.
        DATA lv_message_attr3 TYPE symsgv.
        DATA lv_message_attr4 TYPE symsgv.
    
        CREATE OBJECT lr_busi_exception.
        CALL METHOD lr_busi_exception->get_msg_container
          RECEIVING
            ro_message_container = lr_mcontainer.
    
        lv_message_text = 'Error'.
        lv_message_attr1 = ''.
        lv_message_attr2 = ''.
        lv_message_attr3 = ''.
        lv_message_attr4 = ''.
    
        lr_mcontainer->add_message(
          EXPORTING
            iv_msg_type   = 'E'
            iv_msg_id     = 'MY_CUSTOM_CODE'
            iv_msg_number = 001
            iv_msg_text   = lv_message_text
            iv_msg_v1     = lv_message_attr1
            iv_msg_v2     = lv_message_attr2
            iv_msg_v3     = lv_message_attr3
            iv_msg_v4     = lv_message_attr4
        ).
    
        RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
          EXPORTING
            message_container = lr_mcontainer.
    

    Result:

    {
      "error" : {
        "code" : "MY_CUSTOM_CODE/001",
        "message" : {
          "lang" : "de",
          "value" : "Error"
        },
        "innererror" : {
          "application" : {
            "component_id" : "",
            "service_namespace" : "/XXX/",
            "service_id" : "XXX_SRV",
            "service_version" : "0001"
          },
          "transactionid" : "XXXXXXXXXXXXXXXXXXXX",
          "timestamp" : "XXXXXXXXXXXXXXXXXXXXXXXXX",
          "Error_Resolution" : {
            "SAP_Transaction" : "For backend administrators: use ADT feed reader \"SAP Gateway Error Log\" or 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" : "MY_CUSTOM_CODE/001",
              "message" : "Error",
              "propertyref" : "",
              "severity" : "error",
              "transition" : false,
              "target" : ""
            }
          ]
        }
      }
    }