We have an XData service which we use as a proxy to call another third party service. We need to return the same Status Code and Status Text that we receive from that call.
Does raising an exception help? This is what I've been using, for example, if an endpoint is called without a valid JWT or with some other issue that prevents the service endpoint from working normally.
Although we can live with the standard, is there a way to tell the error that the message is a JSON object so doesn't need the quote marks escaped?
or perhaps provide a more detailed error response such as
{
"errors": [
{
"error": "auth-0001",
"message": "Incorrect username and password",
"detail": "Ensure that the username and password included in the request are correct",
"help": "https://example.com/help/error/auth-0001"
},
...
]
}
The "correct" way to do this in XData is to raise your custom exceptions and handle them in the OnModuleException event.
In that event, you can check if the exception is your special exception type, then get the additional properties from the exception object you want, set Action parameter to Ignore, and then provide the full custom JSON response yourself using the