public ErrorResponse(Exception exception, ErrorHandlingSettings settings) { ErrorCode = "-1"; Type = exception.GetType().Name; HumanReadableMessage = "Server error occured"; if (settings.DeveloperDetails) { DeveloperDetails = new DeveloperDetails(exception); } IsCustom = false; }
public ErrorResponse(CustomException exception, ErrorHandlingSettings settings) { ErrorCode = exception.ErrorCode; Type = exception.GetType().Name; HumanReadableMessage = exception.HumanReadableMessage; if (settings.DeveloperDetails) { DeveloperDetails = new DeveloperDetails(exception); } IsCustom = true; }
// ReSharper disable once UnusedMember.Global - it's called by reflection public async Task Invoke(HttpContext context, ErrorHandlingSettings settings) { try { await next(context); } catch (CustomException exception) { await HandleExceptionAsync( context : context, httpStatusCode : _customHttpStatusCode, errorResponse : new ErrorResponse(exception, settings) ); } catch (Exception exception) { await HandleExceptionAsync( context : context, httpStatusCode : (int)HttpStatusCode.InternalServerError, errorResponse : new ErrorResponse(exception, settings) ); } }