I am looking for the best way (i.e. most maintainable way) to customize the exact exception data on the wire for a small number of my existing service operations.
I really only want to customize for one or two of my services, and even then one or two of my operations of those services. So I am looking to see If I can do this in a ResponseFilterAttribute
ideally, that I can slap onto specific operations.
What I need to do is comply with (RFC6749 OAuth 2.0), and return errors as a serialized JSON structure.
Currently, my service is existing and is setup as a standard service with a DTO that has a ResponseStatus property (as recommended).
public class MyRequestDtoResponse
{
public ResponseStatus ReponseStatus { get; set; }
}
Presently, errors are coming back on the wire like so:
{
"ResponseStatus": {
"ErrorCode": "RuleViolationException",
"Message": "{\"error\":\"invalid_grant\",\"error_description\":\"Client authentication failed. (rfc6749)\"}",
"Errors": []
}
}
What I think RFC6749 needs me to return is:
{
"error": "invalid_grant",
"error_description": "Client authentication failed. (rfc6749)"
}
which, you can see, is already present in the ResponseStatus.Message
already, just how I want it.
Can I create a ResponseFilter
that will give me what I need?
How would that work?
(p.s. already utilize Config.MapExceptionToStatusCode
to map my specific exceptions to specific status codes across my services, and custom code in OnExceptionTypeFilter
. I don’t want to interfere with any of that for these specific operations.)