Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Commit

Permalink
Add catch error to method getResponseBody()
Browse files Browse the repository at this point in the history
  • Loading branch information
Yzermanv committed Dec 16, 2020
1 parent 54d871a commit 17c9132
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/request-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ module.exports = {
const response = await request(method, url, options);
log(`Server responded with status code: '${response.statusCode}' and body: ${response.body.toString()}'`);

this.catchError(response);

return response;
},

getResponseBody(response) {
this.catchError(response);
const body = response.body.toString();

return body ? JSON.parse(body) : {};
},

catchError(response) {
const {statusCode} = response;
const body = response.body.toString();

if (!this.isSuccess(statusCode)) {
const body = response.body.toString();
throw new Error(`Oops, the server responded with status code: '${statusCode}' and body: ${body}`);
}
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@macpaw/qa-api-services",
"version": "2.0.0",
"version": "2.1.0",
"description": "QA API libraries for MacPaw projects",
"main": "index.js",
"author": "Volodymyr Dobrygin",
Expand Down

0 comments on commit 17c9132

Please sign in to comment.