HandleExceptionsAttribute Class |
Namespace: CMS.WebApi
public class HandleExceptionsAttribute : ExceptionFilterAttribute
The HandleExceptionsAttribute type exposes the following members.
Name | Description | |
---|---|---|
HandleExceptionsAttribute |
Creates new instance of HandleExceptionsAttribute.
| |
HandleExceptionsAttribute(IEventLogService) |
Creates new instance of HandleExceptionsAttribute |
Name | Description | |
---|---|---|
OnException |
Raises the exception event.
(Overrides ExceptionFilterAttribute.OnException(HttpActionExecutedContext).) |
[HandleExceptions] public class MyController : ApiController { public HttpResponseMessage GetValue() { ... if(!IsAuthorized(MembershipContext.AuthenticatedUser)) { // 401 status code Unauthorized is returned to the caller, so browser can handle the response properly throw new UnauthorizedAccessException(); } ... } }
[HandleExceptions] public class MyController : ApiController { public HttpResponseMessage GetValue() { ... // 400 status code Bad request is returned to the caller together with the error message throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Given property is in invalid format")) } }
[HandleExceptions] public class MyController : ApiController { public HttpResponseMessage GetValue() { ... // 500 status code Internal server error is returned to the caller. All sensitive data like error message or stack trace are omitted // Exception is logged to the Event log throw new Exception() } }