internal async Task ExceptionHandler(HttpContext context)
        {
            var ex = context.Features.Get <IExceptionHandlerFeature>()?.Error;

            if (ex == null)
            {
                return;
            }

            var error = ApiErrorFactory.Build(context, ex, _mapper, _logger, _env.IsDevelopment(), _exceptionListeners);
            await JsonSerializer.SerializeAsync(context.Response.Body, error, _serializerOptions);
        }
        internal async Task ExceptionHandler(HttpContext context)
        {
            var ex = context.Features.Get <IExceptionHandlerFeature>()?.Error;

            if (ex == null)
            {
                return;
            }

            var error = ApiErrorFactory.Build(context, ex, _mapper, _logger, _env.IsDevelopment(), _exceptionListeners);

            using (var writer = new StreamWriter(context.Response.Body))
            {
                _serializer.Serialize(writer, error);
                await writer.FlushAsync().ConfigureAwait(false);
            }
        }