public CuriosityExceptionHandleMiddleware(
            RequestDelegate next,
            ILogger <CuriosityExceptionHandleMiddleware> logger,
            IOptions <CuriosityExceptionHandlerOptions> options)
        {
            _next    = next ?? throw new ArgumentNullException(nameof(next));
            _logger  = logger ?? throw new ArgumentNullException(nameof(logger));
            _options = options?.Value ?? throw new ArgumentNullException(nameof(options));

            _clearCacheHeadersDelegate = ClearCacheHeaders;

            if (_options.ExceptionHandlingPath == null)
            {
                throw new InvalidOperationException($"{nameof(_options.ExceptionHandlingPath)} can't be empty.");
            }

            _exceptionHandler = _next;
        }
        /// <summary>
        /// Adds a middleware to the pipeline that will catch exceptions, and re-execute the request in an alternate pipeline.
        /// The request will not be re-executed if the response has already started.
        /// The request will not be logged.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public static IApplicationBuilder UseCuriosityExceptionHandler(this IApplicationBuilder app, CuriosityExceptionHandlerOptions options)
        {
            if (app == null)
            {
                throw new ArgumentNullException(nameof(app));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            return(app.UseMiddleware <CuriosityExceptionHandleMiddleware>(Options.Create(options)));
        }