Beispiel #1
0
        public void OnException(ExceptionContext context)
        {
            if (context.Exception is ApiException exception)
            {
                var response = new ApiResponseWithException(exception);

                context.Result = new ApiErrorResult(response);
                return;
            }

            context.Result = new ApiErrorResult(HttpStatusCode.InternalServerError, context.Exception.Message);
        }
Beispiel #2
0
        public async Task Invoke(HttpContext context)
        {
            ApiResponse response;

            try
            {
                await _next.Invoke(context);

                response = new ApiResponse(context.Response.StatusCode);
            }
            catch (ApiException e)
            {
                _telemetryClient.TrackException(e);
                response = new ApiResponseWithException(e);
            }
            catch (Exception e)
            {
                _telemetryClient.TrackException(e);
                response = new ApiResponse(500);
            }

            await ApiResponseAsync(context, response);
        }