First, the main GW log is located in /IWFND/ERROR_LOG
tcode. It holds both system and custom Gateway errors, and looks like this

The general approach to do error logging in SAP Gateway is:
- Put your custom error message and raise business exception in JSON parameter validation method
It is done while getting input parameters, it can be a GetEntity
or CreateEntity
method of MPC_EXT class. As we speak about order creation, probably it will be a CreateEntity
, and there you can analyze the structure of the JSON string and validate it. Analyzing JSON is out of the scope of this question.
- When errors are found the exception will be fired and it will be showed both in log and in browser console

There are two main types of exceptions in Gateway: /iwbep/cx_mgw_busi_exception
and /iwbep/cx_mgw_tech_exception
, but as we want to inject custom logic, our choice is the former.
General approach to implement the exception-handling is:
IF json_invalid = abap_true.
DATA(lo_message_container) = me->mo_context->get_message_container( ).
lo_message_container->add_message( iv_msg_type = /iwbep/cl_cos_logger=>error
iv_msg_number = '100'
iv_msg_id = 'ZJSO'
iv_add_to_response_header = abap_true
).
RAISE EXCEPTION TYPE /iwbep/cx_mgw_busi_exception
EXPORTING
message_container = lo_message_container.
Important: do not miss iv_add_to_response_header = abap_true
parameter when adding the message, thus you will be able to read error messages directly in response without going to logs.
As your business requirement consists of creating order from JSON, probably you will need
add_messages_from_bapi
method:
lo_message->add_messages_from_bapi( it_bapi_messages = lt_return_msg ).
it eats this exact BAPIRET2 structure that comes from your order creation BAPI.
Finally, after all done it worth tracing payload via /IWFND/TRACE
to check what payload comes to front-end.