public override void OnException(ExceptionContext context) { var urlHelper = (IUrlHelper)context.HttpContext.RequestServices.GetService(typeof(IUrlHelper)); switch (context.Exception) { case PagingValidationException pagingValidationException: PageHateoasResponse pagingErrorResponse = ProcessPagingValidationException(pagingValidationException, context, this.stringResources.PageStringResources, urlHelper); context.Result = new BadRequestObjectResult(pagingErrorResponse); break; case ValidationException validationException: BaseHateoasResponse validationErrorResponse = ProcessValidationException(validationException); context.Result = new BadRequestObjectResult(validationErrorResponse); break; case SqlException _: BaseHateoasResponse sqlErrorResponse = ProcessSqlException(stringResources); context.Result = new BadRequestObjectResult(sqlErrorResponse); break; case Exception exception: BaseHateoasResponse errorResponse = ProcessException(exception); context.Result = new BadRequestObjectResult(errorResponse); break; } context.ExceptionHandled = true; }
private static BaseHateoasResponse ProcessValidationException(ValidationException pagingValidationException) { var errorResponse = new BaseHateoasResponse { Errors = pagingValidationException.ValidationMessages, }; return(errorResponse); }