Skip to content

Commit

Permalink
fix: do not cache 200 requests with bad JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandrpravosudko-okta committed Jul 5, 2021
1 parent beee747 commit d018c1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/fetch/fetchRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function fetchRequest(method: string, url: string, args: FetchOptions) {
return formatResult(status, data);
})
.then(result => {
if (error) {
if (error || result.responseJSON?.error) {
// Throwing result object since error handling is done in http.js
throw result;
}
Expand Down
25 changes: 25 additions & 0 deletions test/spec/fetchRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,31 @@ describe('fetchRequest', function () {
errorSummary: 'Could not parse server response'
};

expect.assertions(1);
return fetchRequest(requestMethod, requestUrl, {})
.catch(err => {
expect(err).toEqual({
status: response.status,
responseText: JSON.stringify(errorJSON),
responseJSON: errorJSON,
responseType: 'json'
});
});
});

it('throws if JSON can not be parsed from successful response', () => {
var error = new Error('A fake error, ignore me');
response.status = 200;
response.ok = true;
response.json = function() {
return Promise.reject(error);
};

var errorJSON = {
error: error,
errorSummary: 'Could not parse server response'
};
expect.assertions(1);
return fetchRequest(requestMethod, requestUrl, {})
.catch(err => {
expect(err).toEqual({
Expand Down

0 comments on commit d018c1b

Please sign in to comment.