I have multiple API versions that uses the same AppHost, which is why I don't want to modify the static JsConfig--I only want the HttpError response to be serialized using a scoped JsConfig. I tried using:
throw new HttpError(statuscode){
Response = errorResponseDto,
ResultScope = () => JsConfig.With(...)
};
and also attempted using:
UncaughtExceptionHandlers.Add(async (req, res, name, exception) =>
{
await res.WriteErrorToResponse(req, req.ContentType, req.OperationName, "test", new Exception("test2"), 401);
});
but not sure how to apply the scoped JsConfig in this case. Am I missing something here? Is this possible at all?
Add: if it matters at all, I'm trying to return the error response in camel case, but only for the specific API version which returns responses in camel case as well.
You can use custom scope around WriteErrorToResponse:
using (JsConfig.With(...)) {
await res.WriteErrorToResponse(req)
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With