Skip to content

Commit

Permalink
Merge pull request #450 from vlucas/inspectOnFailure
Browse files Browse the repository at this point in the history
Fix #418 - Add 'inspectOnFailure' true by default
  • Loading branch information
vlucas committed Mar 7, 2018
2 parents ac36a47 + 3aa45af commit 27e4090
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -5,7 +5,7 @@
"homepage": "http://frisbyjs.com",
"author": "Vance Lucas <vance@vancelucas.com>",
"license": {
"type": "BSD"
"type": "BSD-3-Clause"
},
"repository": {
"type": "git",
Expand Down
1 change: 1 addition & 0 deletions src/frisby.js
Expand Up @@ -19,6 +19,7 @@ const _globalSetupDefaults = {
'Content-Type': 'application/json',
'User-Agent': 'frisby/' + version + ' (+https://github.com/vlucas/frisby)',
},
inspectOnFailure: true,
timeout: 5000,
},
};
Expand Down
24 changes: 18 additions & 6 deletions src/frisby/spec.js
Expand Up @@ -228,7 +228,7 @@ class FrisbySpec {
} else {
return response;
}
}, err => onRejected ? onRejected(err) : Promise.reject(err));
}, this._handleError(onRejected));
return this;
}

Expand All @@ -247,10 +247,24 @@ class FrisbySpec {
*/
catch(onRejected) {
this._ensureHasFetched();
this._fetch = this._fetch.catch(err => onRejected ? onRejected(err) : Promise.reject(err));
this._fetch = this._fetch.catch(this._handleError(onRejected));
return this;
}

_handleError(onRejected) {
return (err) => {
if (onRejected) {
return onRejected(err);
}

if (this._setupDefaults.request.inspectOnFailure) {
this.inspectLog("\nFAILURE JSON:", JSON.stringify(this._response.json, null, 4));
}

return Promise.reject(err);
}
}

/**
* Return internal promise used by Frisby.js
* Note: Using this will break the chainability of Frisby.js method calls
Expand Down Expand Up @@ -320,10 +334,8 @@ class FrisbySpec {
});
}

inspectLog() {
let params = Array.prototype.slice.call(arguments);

console.log.apply(null, params); // eslint-disable-line no-console
inspectLog(...args) {
console.log.call(null, ...args); // eslint-disable-line no-console
return this;
}

Expand Down

0 comments on commit 27e4090

Please sign in to comment.