Best Way to override returned HTTP Error Code

I have a service that is wrapping calls to a 3rd Party . As the documentation points out, ServiceStack will return exceptions thrown as a 500 HTTP status code.

I realize that I can us Config.MapExceptionToStatusCode to map codes; however, I would like to examine the exception thrown by 3rd party dll and dynamically map to the status code. What is the best way to do that? I have looked at the OnExceptionTypeFilter but it doesn’t appear to handle the StatusCode.

Thank you in advance.

You could put a try/catch around the calls to the 3rd Party API and throw/return the custom HttpError you wish or you can wrap it inside your own custom Exception that implements IHasStatusCode to control the Status Code returned and IResponseStatusConvertible to control the custom Error ResponseStatus returned.

If you’re using the latest v5.5 you can also override OnExceptionAsync() in your Service and return a custom HTTP Error response (return null for default behavior).