@@ -22,31 +22,17 @@ IOptions<ErrorHandlerOptions> errorHandlerOptions
2222 _errorHandlerOptions = errorHandlerOptions ? . Value ?? throw new ArgumentNullException ( nameof ( errorHandlerOptions ) ) ;
2323 }
2424
25- internal ProblemDetailsResponse Create ( HttpContext httpContext )
25+ internal ErrorProblemDetails Create ( HttpContext httpContext )
2626 {
27- var result = new ProblemDetailsResponse ( ) ;
27+ var problemDetails = new ErrorProblemDetails ( ) ;
2828
29- result . Status = httpContext . GetStatusCode ( ) ?? 0 ; // Default value is 0
30- if ( _apiBehaviorOptions . ClientErrorMapping . TryGetValue ( result . Status , out var clientErrorData ) )
31- {
32- result . Type = clientErrorData . Link ;
33- result . Title = clientErrorData . Title ;
34- }
35- else
36- {
37- result . Type = ProblemDetailsDefaults . Defaults [ 0 ] . Link ;
38- result . Title = ProblemDetailsDefaults . Defaults [ 0 ] . Title ;
39- }
40-
41- result . Instance = httpContext . GetRequestEndpoint ( ) ;
42-
43- result . TraceId = httpContext . GetCorrelationId ( ) ;
29+ _applyDefaults ( httpContext , problemDetails ) ;
4430
45- return result ;
31+ return problemDetails ;
4632 }
4733
4834
49- public ProblemDetailsResponse Create ( HttpContext httpContext , IEnumerable < KeyValuePair < string , string > > errors )
35+ public ErrorProblemDetails Create ( HttpContext httpContext , IEnumerable < KeyValuePair < string , string > > errors )
5036 {
5137 var result = Create ( httpContext ) ;
5238
@@ -62,7 +48,7 @@ public ProblemDetailsResponse Create(HttpContext httpContext, IEnumerable<KeyVal
6248 return result ;
6349 }
6450
65- internal ProblemDetailsResponse Create ( ActionContext actionContext )
51+ internal ErrorProblemDetails Create ( ActionContext actionContext )
6652 {
6753 var payloadTooLargeError = actionContext . ModelState . CheckPayloadTooLargeAndReturnError ( ) ;
6854 if ( payloadTooLargeError . Count == 1 )
@@ -93,7 +79,7 @@ public override ProblemDetails CreateProblemDetails(
9379 string instance = null
9480 )
9581 {
96- statusCode ??= httpContext . GetStatusCode ( ) ?? 0 ;
82+ statusCode ??= httpContext . GetStatusCode ( ) ;
9783
9884 var problemDetails = new ProblemDetails
9985 {
@@ -124,7 +110,7 @@ public override ValidationProblemDetails CreateValidationProblemDetails(
124110 throw new ArgumentNullException ( nameof ( modelStateDictionary ) ) ;
125111 }
126112
127- statusCode ??= httpContext . GetStatusCode ( ) ?? 400 ;
113+ statusCode ??= httpContext . GetStatusCode ( ) ;
128114
129115 var problemDetails = new ValidationProblemDetails ( modelStateDictionary )
130116 {
@@ -147,6 +133,8 @@ public override ValidationProblemDetails CreateValidationProblemDetails(
147133
148134 private void _applyDefaults ( HttpContext httpContext , ProblemDetails problemDetails )
149135 {
136+ problemDetails . Status ??= httpContext . GetStatusCode ( ) ;
137+
150138 if ( _apiBehaviorOptions . ClientErrorMapping . TryGetValue ( problemDetails . Status . Value , out var clientErrorData ) )
151139 {
152140 problemDetails . Type ??= clientErrorData . Link ;
@@ -179,7 +167,7 @@ private static void _applyDetails(ProblemDetails problemDetails)
179167 404 => "The entity was not found." ,
180168 409 => "The entity already exists." ,
181169
182- _ when problemDetails . Status >= 400 && problemDetails . Status < 500 => "A validation error has occurred." ,
170+ _ when problemDetails . Status >= 400 && problemDetails . Status < 500 => "One or more validation errors occurred." ,
183171
184172 _ => "An unexpected error has occurred."
185173 } ;
0 commit comments