Skip to content

Commit e889d79

Browse files
committed
process 400 error responses from token endpoint
1 parent 1ab62d7 commit e889d79

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

src/JsonService.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff 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() {

0 commit comments

Comments
 (0)