Home > Blockchain >  api implementation - is this the right approach ? ( Mule 4.4 )
api implementation - is this the right approach ? ( Mule 4.4 )

Time:05-01

I am implementing a GET request which needs to interact with an ERP and extract employee details . enter image description here Now the interaction with ERP is not using HTTP so it does not return status codes such as 400 etc Any error if present is returned in the XML payload response . Example:

<?xml version="1.0" encoding="utf8" ?>
<Output>
<Error>
    <Status>0</Status>
    <Details>No errors</Details>
</Error>
</Output>

So I have implemented it this way - where after calling ERP and receiving response I check if response contains any error ( errorCode = 0 means an error otherwise all good )

If not an error normal processing , if an error I simply set the http status to 400 and populate response with error details.

Question: In the error flow I am NOT throwing any exception / error and simply returning a response with 400 response status and error details .

My gut feel is in this case there is no need to Raise error ( throw ) and then again catch it in error handler. I thought it is unnecessary in this case but was looking for some feedback ?

Note - the exception handler below is meant to catch errors such as ERP is down / unavailable etc

Note - as this is more a design / approach question , am only pasting screen print of the flow and not the actual code

Please do share your feedback and suggestions

CodePudding user response:

There is no mandate to use Mule Error handling to return an HTTP status, if that's your question.

Note that Mule 4 uses error handling, not exception handling, though it looks similar.

Unrelated, it is strange that you are using HTTP status 400 for a server error, when 400 is meant for bad client request. You may want to use a more proper status.

  • Related