Example #1
0
        public static ProblemDetailsOptions AddDatabaseProblemDetailsExceptionMapping(this ProblemDetailsOptions options)
        {
            options.Map <SqlException>(sqlEx => GetResponseToSqlException(sqlEx));
            options.Map <DbUpdateException>(dbEx => GetResponseToDbUpdateException(dbEx));

            return(options);
        }
Example #2
0
        public static ProblemDetailsOptions AddInvalidInputProblemDetailsExceptionMapping(this ProblemDetailsOptions options)
        {
            options.Map <FormatException>(ex => new StatusCodeProblemDetails(StatusCodes.Status400BadRequest));
            options.Map <JsonException>(ex => new StatusCodeProblemDetails(StatusCodes.Status400BadRequest));
            options.Map <ValidationException>(ex => new StatusCodeProblemDetails(StatusCodes.Status400BadRequest));

            return(options);
        }
Example #3
0
        public static ProblemDetailsOptions AddProblemDetailsExceptionMappingForWhenItsOurFault(this ProblemDetailsOptions options)
        {
            options.Map <InvalidOperationException>(ex => new StatusCodeProblemDetails(StatusCodes.Status500InternalServerError));
            options.Map <NotImplementedException>(ex => new StatusCodeProblemDetails(StatusCodes.Status501NotImplemented));
            options.Map <HttpRequestException>(ex => new StatusCodeProblemDetails(StatusCodes.Status503ServiceUnavailable));
            options.Map <Exception>(ex => new StatusCodeProblemDetails(StatusCodes.Status500InternalServerError));

            return(options);
        }
Example #4
0
        public static ProblemDetailsOptions AddSecurityProblemDetailsExceptionMapping(this ProblemDetailsOptions options)
        {
            /* The 402 code is named "Unauthorized" in the HTTP specification, but the description of the code makes it
             * clear that it means "not authenticated". For a true "unauthorized response, use status code 403 - Forbidden. */
            options.Map <InvalidCredentialException>(ex => new StatusCodeProblemDetails(StatusCodes.Status401Unauthorized));

            options.Map <NotAuthenticatedException>(ex => new StatusCodeProblemDetails(StatusCodes.Status401Unauthorized));
            options.Map <NotAuthorizedException>(ex => new StatusCodeProblemDetails(StatusCodes.Status401Unauthorized));
            return(options);
        }