File tree 2 files changed +35
-4
lines changed
2 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,32 @@ test.each([
55
55
'At least one product must be selected if policy is restricted.' ,
56
56
} ,
57
57
] ,
58
+ [
59
+ 'problem+json' ,
60
+ {
61
+ '@context' : '/contexts/ConstraintViolation' ,
62
+ '@id' : '/validation_errors/2881c032-660f-46b6-8153-d352d9706640' ,
63
+ '@type' : 'ConstraintViolation' ,
64
+ status : 422 ,
65
+ violations : [
66
+ {
67
+ propertyPath : 'isbn' ,
68
+ 'ConstraintViolation/message' :
69
+ 'This value is neither a valid ISBN-10 nor a valid ISBN-13.' ,
70
+ 'ConstraintViolation/code' : '2881c032-660f-46b6-8153-d352d9706640' ,
71
+ } ,
72
+ ] ,
73
+ detail :
74
+ 'isbn: This value is neither a valid ISBN-10 nor a valid ISBN-13.' ,
75
+ description :
76
+ 'isbn: This value is neither a valid ISBN-10 nor a valid ISBN-13.' ,
77
+ type : '/validation_errors/2881c032-660f-46b6-8153-d352d9706640' ,
78
+ title : 'An error occurred' ,
79
+ } ,
80
+ {
81
+ isbn : 'This value is neither a valid ISBN-10 nor a valid ISBN-13.' ,
82
+ } ,
83
+ ] ,
58
84
] ) (
59
85
'%s violation list expanding' ,
60
86
async ( format : string , resBody : object , expected : object ) => {
Original file line number Diff line number Diff line change @@ -68,6 +68,10 @@ const getFieldType = (field: Field) => {
68
68
}
69
69
} ;
70
70
71
+ const getViolationMessage = ( violation : JsonLdObj , base : string ) =>
72
+ violation [ `${ base } #message` ] ??
73
+ violation [ `${ base } #ConstraintViolation/message` ] ;
74
+
71
75
const getSubmissionErrors = ( error : HttpError ) => {
72
76
if ( ! error . body ?. [ 0 ] ) {
73
77
return null ;
@@ -84,15 +88,16 @@ const getSubmissionErrors = (error: HttpError) => {
84
88
85
89
const violations : SubmissionErrors = content [ violationKey ] . reduce (
86
90
( previousViolations : SubmissionErrors , violation : JsonLdObj ) =>
87
- ! violation [ `${ base } #propertyPath` ] || ! violation [ `${ base } #message` ]
91
+ ! violation [ `${ base } #propertyPath` ] ||
92
+ ! getViolationMessage ( violation , base )
88
93
? previousViolations
89
94
: {
90
95
...previousViolations ,
91
96
[ ( violation [ `${ base } #propertyPath` ] as JsonLdObj [ ] ) [ 0 ] ?. [
92
97
'@value'
93
- ] as string ] : ( violation [ ` ${ base } #message` ] as JsonLdObj [ ] ) [ 0 ] ?. [
94
- '@value'
95
- ] ,
98
+ ] as string ] : (
99
+ getViolationMessage ( violation , base ) as JsonLdObj [ ]
100
+ ) [ 0 ] ?. [ '@value' ] ,
96
101
} ,
97
102
{ } ,
98
103
) ;
You can’t perform that action at this time.
0 commit comments