File tree Expand file tree Collapse file tree 1 file changed +20
-9
lines changed
templates/react-common/utils Expand file tree Collapse file tree 1 file changed +20
-9
lines changed Original file line number Diff line number Diff line change @@ -21,17 +21,28 @@ export function fetch(id, options = {}) {
2121 return global . fetch ( new URL ( id , ENTRYPOINT ) , options ) . then ( response => {
2222 if ( response . ok ) return response ;
2323
24- return response . json ( ) . then ( json => {
25- const error = json [ 'hydra:description' ] || response . statusText ;
26- if ( ! json . violations ) throw Error ( error ) ;
24+ return response . json ( ) . then (
25+ json => {
26+ const error =
27+ json [ 'hydra:description' ] ||
28+ json [ 'hydra:title' ] ||
29+ 'An error occurred.' ;
30+ if ( ! json . violations ) throw Error ( error ) ;
2731
28- let errors = { _error : error } ;
29- json . violations . map (
30- violation => ( errors [ violation . propertyPath ] = violation . message )
31- ) ;
32+ let errors = { _error : error } ;
33+ json . violations . forEach ( violation =>
34+ errors [ violation . propertyPath ]
35+ ? ( errors [ violation . propertyPath ] +=
36+ '\n' + errors [ violation . propertyPath ] )
37+ : ( errors [ violation . propertyPath ] = violation . message )
38+ ) ;
3239
33- throw new SubmissionError ( errors ) ;
34- } ) ;
40+ throw new SubmissionError ( errors ) ;
41+ } ,
42+ ( ) => {
43+ throw new Error ( response . statusText || 'An error occurred.' ) ;
44+ }
45+ ) ;
3546 } ) ;
3647}
3748
You can’t perform that action at this time.
0 commit comments