/// <summary>
        /// Maps exception to an HTTP status code.
        /// </summary>
        /// <typeparam name="TBuilder">The type of the builder.</typeparam>
        /// <param name="builder">The builder.</param>
        /// <param name="statusCode">The response status code.</param>
        public static TBuilder ToStatusCode <TBuilder>(
            this TBuilder builder,
            int statusCode)
            where TBuilder : EndpointExceptionMappingConventionBuilder
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            return(builder.ToRequestHandler(
                       EndpointExceptionMappingFunctions.ToStatusCode(statusCode)));
        }
        /// <summary>
        /// TODO: Internal for now until implemented. Maps exception to a named exception handler.
        /// </summary>
        /// <typeparam name="TBuilder">The type of the builder.</typeparam>
        /// <param name="builder">The builder.</param>
        /// <param name="name">The name of the exception handler.</param>
        internal static TBuilder ToNamedExceptionHandler <TBuilder>(
            this TBuilder builder,
            string name)
            where TBuilder : EndpointExceptionMappingConventionBuilder
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            return(builder.ToRequestHandler(
                       EndpointExceptionMappingFunctions.ToNamedExceptionHandler(name)));
        }
        /// <summary>
        /// Maps exception to an instance of <see cref="ProblemDetails"/> and writes the instance to response.
        /// </summary>
        /// <typeparam name="TBuilder">The type of the builder.</typeparam>
        /// <param name="builder">The builder.</param>
        /// <param name="problemFactory">The problem details factory.</param>
        public static TBuilder ToProblemDetails <TBuilder>(
            this TBuilder builder,
            Func <ProblemDetailsCreationContext, ProblemDetails> problemFactory)
            where TBuilder : EndpointExceptionMappingConventionBuilder
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (problemFactory == null)
            {
                throw new ArgumentNullException(nameof(problemFactory));
            }

            return(builder.ToRequestHandler(
                       EndpointExceptionMappingFunctions.ToProblemDetails(problemFactory)));
        }
        /// <summary>
        /// Maps exception to another endpoint.
        /// </summary>
        /// <typeparam name="TBuilder">The type of the builder.</typeparam>
        /// <param name="builder">The builder.</param>
        /// <param name="pattern">The route pattern.</param>
        /// <param name="routeValues">The route values.</param>
        public static TBuilder ToEndpoint <TBuilder>(
            this TBuilder builder,
            string pattern,
            object?routeValues = null)
            where TBuilder : EndpointExceptionMappingConventionBuilder
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (pattern == null)
            {
                throw new ArgumentNullException(nameof(pattern));
            }

            return(builder.ToRequestHandler(
                       EndpointExceptionMappingFunctions.ToEndpoint(pattern, routeValues)));
        }