Custom 400 return type (application/fhir+xml)
Currently working on an API that has to be FHIR compliant. FHIR has it's own conventions for dealing with for example a 400.
I wrote a middleware to handle with these. It works fine for 401,403 and 404 errors. However as soon as I attempt this on a 400 I get this exception:
The code used to write the custom error to the response:
This is the same code in the same loccation that also handles the 404 errors. And for those it works perfect. It seems ASP starts writing the instant a controller method returns a "BadRequest". How do I stop that behaviour?
6 Replies
Where does this code live?
Middleware
Hm... this looks potentially promising?
https://hanson.io/aspnet-setting-cookies-in-middleware/#final-pass
they make use of
context.Response.OnStarting
, not sure if that'd be applicable here
also, middleware order can matter, but if what you've show is all your middleware, LGTM on that frontI think this will work thanks
It worked! thanks
awesome, happy to help!