Пример #1
0
        private bool TryHandleException(ExceptionContext context)
        {
            switch (context.Exception)
            {
            case NotFoundException _:
                context.ExceptionHandled = true;
                context.HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                context.Result = new ObjectResult(new StandardResponse(ResponseType.NotFound()));
                return(true);

            case UnauthorizedException _:
                context.ExceptionHandled = true;
                context.HttpContext.Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                context.Result = new ObjectResult(new StandardResponse(ResponseType.Unauthorised()));
                return(true);

            case ValidationException exception:
                context.ExceptionHandled = true;
                context.HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
                context.Result = new ObjectResult(new StandardResponse(ResponseStatus.Invalid, exception.Message, exception.Errors));
                return(true);
            }
            return(false);
        }