AspNetCore exception-based error handler
For existing exceptions, a simple attribute to define the returning status code.
[StatusCode(400)]
class MyException : Exception
{
...
}
To define a new exception which is going to be handled, use HttpException
as your parent class.
class MyException : HttpException {
public MyException()
: base(400)
{}
}
To create a user-friendly response message
class MyException : HttpException, IExplainableException {
public MyException()
: base(400)
{}
object Explain() {
return "Could not finish the example.";
}
}