larshp / ABAP-Swagger

Expose ABAP REST services with Swagger/openapi spec
MIT License
97 stars 40 forks source link

catching all exceptions of handler method #63

Closed BlackmanCC closed 3 years ago

BlackmanCC commented 3 years ago

In the current implementation exceptions of the handler method have to be of type zcx_swag. The only limitiation for using methods as handler methods is that they should ony have one returning parameter.

I think it would be better to catch cx_root so that we also can use handler methods throwing non zx_swag exceptions.

`

    TRY.
        CALL METHOD <ls_meta>-obj->(<ls_meta>-meta-handler)

          PARAMETER-TABLE lt_parameters.
      CATCH zcx_swag INTO lx_swag.
        mi_server->response->set_cdata( |{ lx_swag->status_code }, { lx_swag->get_text( ) }| ).
        mi_server->response->set_status( code = lx_swag->status_code reason = lx_swag->get_text( ) ).
        RETURN.
    ENDTRY.

`

@larshp What do you think?