I want to return error responses in the RFC7807 format. It’s just a json response with standardized properties. Setting it all up has been no problem, but getting ServiceStack to return the json to the client has not been successful.
My code:
CustomErrorHttpHandlers[HttpStatusCode.NotFound] = new CustomResponseHandler((httpReq, httpRes) =>
{
httpReq.ResponseContentType = RFC7807ProblemDetails.PROBLEM_JSON_MIME_TYPE; //application/problem+json
return new HttpError(/*dto creation omitted for brevity/*, HttpStatusCode.NotFound, "Not Found", null) { ContentType = RFC7807ProblemDetails.PROBLEM_JSON_MIME_TYPE };
});
In that example I have tried 2 ways to set the response content type, as you can see. However, that causes a crash in both cases:
ContentType not supported 'application/problem+json'
Any tips on getting around this block? This might be worth adding formal support for.