public static void UpdateApiErrorResponse(HttpContext context, Exception ex, ApiError error) { string name = ex.GetType().Name; error.Data = name switch { nameof(ValidationException) => new ApiErrorData(JsonConvert.SerializeObject(((ValidationException)ex).ValdationErrors)), nameof(BadRequestException) => new ApiErrorData(ex.Message, LinkConstants.BadRequestException), nameof(NotFoundException) => new ApiErrorData(ex.Message, LinkConstants.NotFoundException), nameof(NullReferenceException) => new ApiErrorData(ExceptionConstants.NullReferenceException, LinkConstants.NullReferenceException), nameof(TimeoutException) => new ApiErrorData(ExceptionConstants.TimeoutException, LinkConstants.TimeoutException), nameof(SqlException) => new ApiErrorData(ExceptionConstants.SqlException, LinkConstants.SqlException), nameof(Exception) => new ApiErrorData(ExceptionConstants.Exception, LinkConstants.Exception), _ => new ApiErrorData(name) }; string requestMessage = MessageHelpers.BuildRequestMessage(context.Request); string responseMessage = MessageHelpers.BuildResponseMessage(error); Log.Logger.Information(responseMessage + Environment.NewLine + Environment.NewLine + requestMessage); }