<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: ABAP RESTful Application Programming Model Behaviours - How do  I implement exception handling? in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/abap-restful-application-programming-model-behaviours-how-do-i-implement/qaa-p/12530922#M4697352</link>
    <description>&lt;P&gt;Thanks  &lt;SPAN class="mention-scrubbed"&gt;andre.fischer&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;Here's my solution with a couple of changes.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I've used a blank message (id 00, number 001),&lt;/LI&gt;&lt;LI&gt;As the location and format of the exception is different depending on the http code, I've used the iwbep/cx_gateway-&amp;gt;get_text() for http 500 errors, otherwise get_longtext().&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; TYPES: BEGIN OF ty_longtext,
             msgv1(50),
             msgv2(50),
             msgv3(50),
             msgv4(50),
           END OF ty_longtext.
    DATA: ls_longtext      TYPE ty_longtext.
...
  CATCH /iwbep/cx_gateway INTO DATA(lx_gateway).

        IF lx_gateway-&amp;gt;http_status_code = 500.
          ls_longtext = lx_gateway-&amp;gt;get_text(  ).
        ELSE.
          ls_longtext =  Lx_gateway-&amp;gt;get_longtext(  ).
        ENDIF.

 APPEND VALUE #(
            %msg = new_message(
            id      = '00'
            number      = 001
            severity  = if_abap_behv_message=&amp;gt;severity-error
            v1      = ls_longtext-msgv1
            v2      = ls_longtext-msgv2
            v3      = ls_longtext-msgv3
            v4      = ls_longtext-msgv4
            )
        ) TO reported-salesorderitem.

APPEND VALUE #(
            %create = if_abap_behv=&amp;gt;mk-on
        ) TO failed-salesorderitem&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 04 Feb 2022 13:19:40 GMT</pubDate>
    <dc:creator>adamharkus</dc:creator>
    <dc:date>2022-02-04T13:19:40Z</dc:date>
    <item>
      <title>ABAP RESTful Application Programming Model Behaviours - How do  I implement exception handling?</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-restful-application-programming-model-behaviours-how-do-i-implement/qaq-p/12530918</link>
      <description>&lt;P&gt;Currently I'm implementing an &lt;STRONG&gt;&lt;EM&gt;unmanaged &lt;/EM&gt;&lt;/STRONG&gt;CREATE behaviour, but the error handling is too generic at the moment..&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;TRY 

...
 DATA(request) = client_proxy-&amp;gt;create_resource_for_entity_set( 'A_SALESORDERITEM' )-&amp;gt;create_request_for_create( ).

        APPEND 'SALESORDER'            TO so_item_properties.
        APPEND 'MATERIAL'              TO so_item_properties.
        APPEND 'REQUESTEDQUANTITY'     TO so_item_properties.
        APPEND 'REQUESTEDQUANTITYUNIT' TO so_item_properties.
...
          request-&amp;gt;set_business_data(
            is_business_data    = items
            it_provided_property = so_item_properties
          ).

...
CATCH /iwbep/cx_gateway.
        APPEND VALUE #(
          symsg-msgty      = 'E'
          symsg-msgid      = '/N4C02/CM_HTTP_COMM'
          symsg-msgno      = '006'
          severity         = if_abap_behv_message=&amp;gt;severity-error
          cid              = sales_order_item_out-cid
        ) TO messages.

        APPEND VALUE #(
            %cid    = sales_order_item_out-cid
            %create = if_abap_behv=&amp;gt;mk-on
        ) TO failed-salesorderitem.
    
...
ENDTRY.&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;The above merely throws a generic error for all gateway errors which is reported in the Fiori Elements app.&lt;/P&gt;
  &lt;P&gt;How do I specifically handle &lt;STRONG&gt;&lt;EM&gt;each and every Gateway exception caught in iwbep/cx_gateway ?&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
  &lt;P&gt;E.g. the Gateway is current throwing an exception of&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;No language-specific unit defined in language EN for internal unit T  &lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;... This is for entering a non-existent Quantity unit of T.&lt;/P&gt;
  &lt;P&gt;The issue is the end-user doesn't see this.... All they get is the generic 'Gateway Exception' error.&lt;/P&gt;
  &lt;P&gt;I know I can catch this info using something like...&lt;/P&gt; 
  &lt;PRE&gt;&lt;CODE&gt;CATCH /iwbep/cx_gateway INTO DATA(lx_gateway).&lt;/CODE&gt;&lt;/PRE&gt;
  &lt;P&gt;However, I have a number of issues with what is being return in lx_gateway above.&lt;/P&gt;
  &lt;P&gt;Firstly, accessing it is problematic as it's an object with attached methods to retrieve data (e.g. get_text( ) ).&lt;/P&gt;
  &lt;P&gt;Secondly, the data format looks to depend on the error, here are some scenarios I've tested.&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;1) Everything correct apart from an invalid RequestedQuantityUnit.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
  &lt;P&gt;500 HTTP status&lt;/P&gt;
  &lt;P&gt;MSGID BM&lt;/P&gt;
  &lt;P&gt;MSGNO 302&lt;/P&gt;
  &lt;P&gt;MSGV1 pce&lt;/P&gt;
  &lt;P&gt;MSGV2 EN&lt;/P&gt;
  &lt;P&gt;MSGV3 &lt;/P&gt;
  &lt;P&gt;MSGV4 &lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;2) Everything correct apart from a blank Material.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
  &lt;P&gt;400 HTTP status&lt;/P&gt;
  &lt;P&gt;Unlike the above error, no message properties are returned, but we do have an &lt;/P&gt;
  &lt;P&gt;HTTP_ERROR_BODY property.&lt;/P&gt;
  &lt;P&gt;&lt;EM&gt;{"error":{"code":"V1/320","message":{"lang":"en","value":"No item category available (Table T184 OR TEXT )"},"innererror":{"application":{"component_id":"SD-SLS-SO","service_namespace":"/SAP/","service_id":"API_SALES_ORDER_SRV","service_version":"0001"},"transactionid":"64205A9E09A00030E0061F9CEDB7A798","timestamp":"","Error_Resolution":{"SAP_Transaction":"","SAP_Note":"See SAP Note 1797736 for error analysis (https://service.sap.com/sap/support/notes/1797736)"},"longtext_url":"/sap/opu/odata/iwbep/message_text;o=BACKEND/","errordetails":[{"ContentID":"","code":"/IWBEP/CX_MGW_BUSI_EXCEPTION","message":"No item category available (Table T184 OR TEXT )","longtext_url":"/sap/opu/odata/iwbep/message_text;o=BACKEND/","propertyref":"","severity":"error","transition":false,"target":""}]}}}&lt;/EM&gt;&lt;/P&gt;
  &lt;P&gt;&lt;EM&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;
  &lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;3) No properties entered.&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
  &lt;P&gt;Although they are set to Mandatory in the Behaviour Definition, /iwbep/cx_gateway IS NOT CAUGHT.&lt;/P&gt;
  &lt;P&gt;I've tried to include as much detail as possible but just to clarify, the 2 issues are: &lt;/P&gt;
  &lt;P&gt;a) I need a consistent way of trapping all exceptions, so I can populate the messages table, which sets up the returned message(s) back to the UI.&lt;/P&gt;
  &lt;P&gt;b) I need to be able to catch all Mandatory fields that haven't been populated.&lt;/P&gt;
  &lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Feb 2022 16:50:02 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-restful-application-programming-model-behaviours-how-do-i-implement/qaq-p/12530918</guid>
      <dc:creator>adamharkus</dc:creator>
      <dc:date>2022-02-01T16:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP RESTful Application Programming Model Behaviours - How do  I implement exception handling?</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-restful-application-programming-model-behaviours-how-do-i-implement/qaa-p/12530919#M4697349</link>
      <description>&lt;P&gt;You have to fill the reported response parameter.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;       
    TYPES: BEGIN OF ty_longtext,
             msgv1(50),
             msgv2(50),
             msgv3(50),
             msgv4(50),
           END OF ty_longtext.
    DATA: ls_longtext      TYPE ty_longtext.


      APPEND VALUE #( %tky = keys[ 1 ]-%tky )
                         TO failed-rapgeneratorbo.
        APPEND VALUE #( %tky = keys[ 1 ]-%tky
                 %msg = new_message(
                          id       = '/DMO/CM_RAP_GEN_MSG'
                          number   = 064
                          severity = if_abap_behv_message=&amp;gt;severity-error
                          v1       = |{ ls_longtext-msgv1 }|
                          v2       = |{ ls_longtext-msgv2 }|
                        )
                         )
        TO reported-rapgeneratorbo.


&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Feb 2022 18:01:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-restful-application-programming-model-behaviours-how-do-i-implement/qaa-p/12530919#M4697349</guid>
      <dc:creator>Andre_Fischer</dc:creator>
      <dc:date>2022-02-01T18:01:09Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP RESTful Application Programming Model Behaviours - How do  I implement exception handling?</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-restful-application-programming-model-behaviours-how-do-i-implement/qaa-p/12530920#M4697350</link>
      <description>&lt;P&gt;Hi Andre.&lt;/P&gt;&lt;P&gt;I know about the reported response, but the issue is how is the exception caught and populated in the first place?&lt;/P&gt;&lt;P&gt;In your example, that too is hard-coded with a specific ID, number, severity etc, but how can I populate this with the specific exception from the API?&lt;/P&gt;&lt;P&gt;E.g. I'm using API_SALES_ORDER_SRV/A_SalesOrderItem and implemented the CREATE using....&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;    request-&amp;gt;set_business_data(&lt;BR /&gt;            is_business_data    = items&lt;BR /&gt;            it_provided_property = so_item_properties&lt;BR /&gt;          ).&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Feb 2022 18:13:38 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-restful-application-programming-model-behaviours-how-do-i-implement/qaa-p/12530920#M4697350</guid>
      <dc:creator>adamharkus</dc:creator>
      <dc:date>2022-02-01T18:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP RESTful Application Programming Model Behaviours - How do  I implement exception handling?</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-restful-application-programming-model-behaviours-how-do-i-implement/qaa-p/12530921#M4697351</link>
      <description>&lt;P&gt;Extra detail and context has been added to the original question.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Feb 2022 15:52:48 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-restful-application-programming-model-behaviours-how-do-i-implement/qaa-p/12530921#M4697351</guid>
      <dc:creator>adamharkus</dc:creator>
      <dc:date>2022-02-02T15:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: ABAP RESTful Application Programming Model Behaviours - How do  I implement exception handling?</title>
      <link>https://community.sap.com/t5/technology-q-a/abap-restful-application-programming-model-behaviours-how-do-i-implement/qaa-p/12530922#M4697352</link>
      <description>&lt;P&gt;Thanks  &lt;SPAN class="mention-scrubbed"&gt;andre.fischer&lt;/SPAN&gt; &lt;/P&gt;&lt;P&gt;Here's my solution with a couple of changes.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I've used a blank message (id 00, number 001),&lt;/LI&gt;&lt;LI&gt;As the location and format of the exception is different depending on the http code, I've used the iwbep/cx_gateway-&amp;gt;get_text() for http 500 errors, otherwise get_longtext().&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt; TYPES: BEGIN OF ty_longtext,
             msgv1(50),
             msgv2(50),
             msgv3(50),
             msgv4(50),
           END OF ty_longtext.
    DATA: ls_longtext      TYPE ty_longtext.
...
  CATCH /iwbep/cx_gateway INTO DATA(lx_gateway).

        IF lx_gateway-&amp;gt;http_status_code = 500.
          ls_longtext = lx_gateway-&amp;gt;get_text(  ).
        ELSE.
          ls_longtext =  Lx_gateway-&amp;gt;get_longtext(  ).
        ENDIF.

 APPEND VALUE #(
            %msg = new_message(
            id      = '00'
            number      = 001
            severity  = if_abap_behv_message=&amp;gt;severity-error
            v1      = ls_longtext-msgv1
            v2      = ls_longtext-msgv2
            v3      = ls_longtext-msgv3
            v4      = ls_longtext-msgv4
            )
        ) TO reported-salesorderitem.

APPEND VALUE #(
            %create = if_abap_behv=&amp;gt;mk-on
        ) TO failed-salesorderitem&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Feb 2022 13:19:40 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/abap-restful-application-programming-model-behaviours-how-do-i-implement/qaa-p/12530922#M4697352</guid>
      <dc:creator>adamharkus</dc:creator>
      <dc:date>2022-02-04T13:19:40Z</dc:date>
    </item>
  </channel>
</rss>

