Skip to content

Commit 6c725cd

Browse files
committed
Check for JSON before parsing JSON in errors
The createError function was incorrectly assuming that response bodies are in JSON format and attempting to extract useful details from that body. But, for some error cases, the body is not JSON resulting in a error being thrown during the process of adding details to the error. This fix adds safeguards around the places that need JSON to enable the createError method to extract the useful details.
1 parent 7689a66 commit 6c725cd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/OAuthClient.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ OAuthClient.prototype.createError = function createError(e, authResponse) {
585585
e.originalMessage = e.message;
586586

587587
e.error = '';
588-
if ('error' in authResponse.getJson()) {
588+
if (authResponse.isJson() && 'error' in authResponse.getJson()) {
589589
e.error = authResponse.getJson().error;
590590
} else if (authResponse.response.statusText) {
591591
e.error = authResponse.response.statusText;
@@ -594,7 +594,7 @@ OAuthClient.prototype.createError = function createError(e, authResponse) {
594594
}
595595

596596
e.error_description = '';
597-
if ('error_description' in authResponse.getJson()) {
597+
if (authResponse.isJson() && 'error_description' in authResponse.getJson()) {
598598
e.error_description = authResponse.getJson().error_description;
599599
} else if (authResponse.response.statusText) {
600600
e.error_description = authResponse.response.statusText;

0 commit comments

Comments
 (0)