internal MessagingExceptionDetail(ExceptionErrorCodes errorCode, string message, ErrorLevelType errorLevel, HttpStatusCode?httpStatusCode, string trackingId) { this.ErrorCode = (int)errorCode; this.Message = message; this.ErrorLevel = errorLevel; this.HttpStatusCode = httpStatusCode; this.TrackingId = trackingId; }
private Task HandleExceptionAsync(HttpContext context, Exception exception) { ExceptionResponse exceptionResponse; var jsonSerializationEx = exception as JsonSerializationException; var domainEx = exception as DomainException; context.Response.ContentType = "application/json"; _loggingService.Error("An Error has occurred : ", "ExceptionMiddleware.HandleExceptionAsync", exception); if (jsonSerializationEx != null && jsonSerializationEx.Message.Contains("Invalid Request")) { ExceptionErrorCodes errorCode = ExceptionErrorCodes.InvalidRequest; string message = UtilHelpers.GetEnumDescription(errorCode); context.Response.StatusCode = (int)HttpStatusCode.BadRequest; exceptionResponse = new ExceptionResponse(new AssetErrorInfo { ErrorCode = (int)errorCode, Message = string.Format(message, jsonSerializationEx.Message) }); } else if (domainEx != null) { context.Response.StatusCode = (int)HttpStatusCode.BadRequest; exceptionResponse = new ExceptionResponse(GetErrorLists(domainEx)); } else { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; exceptionResponse = new ExceptionResponse(new AssetErrorInfo { Message = "An Unexpected Error has occurred", ErrorCode = (int)ExceptionErrorCodes.UnexpectedError }); } if (string.Compare(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"), EnvironmentName.Development, StringComparison.OrdinalIgnoreCase) == 0) { exceptionResponse.Exception = exception; } return(context.Response.WriteAsync(JsonConvert.SerializeObject(exceptionResponse))); }