velddev / AspNetCore.Exceptions

AspNetCore exception-based error handler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AspNetCore.Exceptions

AspNetCore exception-based error handler

Examples

With attributes

For existing exceptions, a simple attribute to define the returning status code.

[StatusCode(400)]
class MyException : Exception 
{
  ...
}

With parent types

To define a new exception which is going to be handled, use HttpException as your parent class.

class MyException : HttpException {
  public MyException()
    : base(400)
  {}
}

With message

To create a user-friendly response message

class MyException : HttpException, IExplainableException {
  public MyException()
    : base(400)
  {}

  object Explain() {
    return "Could not finish the example.";
  }
}

About

AspNetCore exception-based error handler

License:MIT License


Languages

Language:C# 100.0%