MapExceptionToStatusCode should match also derived types

MapExceptionToStatusCode seems to match only exact type. How can be customize to match also devired type of a specified base type?
We do have a base custom exception MyException : Exception and also few other inheriting from that

Custom1Exception : MyException, Custom2Exception : MyException

I’d like to set somenthig like

MapExceptionToStatusCode = { { typeof(MyException), 400 } }

and have HttpErrorCode = 400 also if I throw Custom1Exception or Custom2Exception

Right Config.MapExceptionToStatusCode only maps specific Exception Types.

You can inherit from ArgumentException to inherit its 400 BadRequest Status code. Inheriting from HttpError will let you customize the HTTP Response even further.

Otherwise you can register a IAppHost.ServiceExceptionHandlers or Response Filter to detect the Exception and change the Response Status Code.

I’ve just added this feature so that you just need to register the base type which sub classes will inherit in this commit.

I’ve also added a new feature that will allow you to customize the Status Code without needing to register it in Config,MapExceptionToStatusCode by having Exceptions implement IHasStatusCode, e.g:

public class Custom401Exception : Exception, IHasStatusCode
{
    public int StatusCode { get { return 401; } }
}

This change is now available from v4.0.43+ that’s now available on MyGet.

Awesome. Thanks a lot.