File tree Expand file tree Collapse file tree 1 file changed +31
-2
lines changed
Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -125,10 +125,39 @@ export class JsonService {
125125 }
126126
127127 reject ( Error ( "Invalid response Content-Type: " + contentType + ", from URL: " + url ) ) ;
128+ return ;
128129 }
129- else {
130- reject ( Error ( req . statusText + " (" + req . status + ")" ) ) ;
130+
131+ if ( req . status === 400 ) {
132+
133+ var contentType = req . getResponseHeader ( "Content-Type" ) ;
134+ if ( contentType ) {
135+
136+ var found = allowedContentTypes . find ( item => {
137+ if ( contentType . startsWith ( item ) ) {
138+ return true ;
139+ }
140+ } ) ;
141+
142+ if ( found ) {
143+ try {
144+ var payload = JSON . parse ( req . responseText ) ;
145+ if ( payload && payload . error ) {
146+ Log . error ( "JsonService.postForm: Error from server: " , payload . error ) ;
147+ reject ( new Error ( payload . error ) ) ;
148+ return ;
149+ }
150+ }
151+ catch ( e ) {
152+ Log . error ( "JsonService.postForm: Error parsing JSON response" , e . message ) ;
153+ reject ( e ) ;
154+ return ;
155+ }
156+ }
157+ }
131158 }
159+
160+ reject ( Error ( req . statusText + " (" + req . status + ")" ) ) ;
132161 } ;
133162
134163 req . onerror = function ( ) {
You can’t perform that action at this time.
0 commit comments