public async Task Invoke(HttpContext context)
        {
            try
            {
                await next(context);
            }
            catch (Exception e)
            {
                Exception ex = e as ApplicationInsightsAlreadyInspectedException;
                if (ex != null)
                {
                    ex = e.InnerException;
                }
                else
                {
                    insight.Exception(e, "ExceptionHandlingMiddleware");
                }

                if (context.Response.HasStarted)
                {
                    throw;
                }

                var errorResponse = new ErrorResponse
                {
                    CorrelationId = CallContext.ClientContext.CorrelationId,
                    Message       = options.HideErrorMessage ? "$(GeneralErrorMessage)" : e.Message,
                    Status        = (int)((e as HttpStatusException)?.Status ?? StatusCode.InternalServerError)
                };

                context.Response.StatusCode  = errorResponse.Status;
                context.Response.ContentType = "application/json";
                await context.Response.WriteAsync(Newtonsoft.Json.JsonConvert.SerializeObject(errorResponse));
            }
        }