Skip to content

Commit

Permalink
Merge pull request #25 from PagerDuty/easierErrorCodes
Browse files Browse the repository at this point in the history
Only attempt to .json() if success response.
  • Loading branch information
Brett Willemsen authored Nov 16, 2020
2 parents d3d57f7 + 32c4a1d commit f4c2e49
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion dist/pdjs-legacy.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pdjs-legacy.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pdjs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pdjs.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pagerduty/pdjs",
"version": "2.0.0",
"version": "2.0.1",
"description": "A new simple JavaScript wrapper for the PagerDuty API",
"main": "build/src/index.js",
"types": "build/src/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion src/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ test('API explodes list based parameters properly', async done => {
});

expect(resp.url).toEqual(
`https://api.pagerduty.com/incidents?additional_fields%5B%5D=one&additional_fields%5B%5D=two&additional_fields%5B%5D=three`
'https://api.pagerduty.com/incidents?additional_fields%5B%5D=one&additional_fields%5B%5D=two&additional_fields%5B%5D=three'
);
done();
});
Expand Down
21 changes: 12 additions & 9 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,19 @@ function apiRequest(url: string, options: RequestOptions): APIPromise {
return request(url, options).then(
(response: Response): APIPromise => {
const apiResponse = response as APIResponse;
apiResponse.response = response;
const resource = resourceKey(url);
return response.json().then(
(data): APIResponse => {
apiResponse.next = nextFunc(url, options, data);
apiResponse.data = data;
apiResponse.resource = resource ? data[resource] : null;
apiResponse.response = response;
return apiResponse;
}
);
return response
.json()
.then(
(data): APIResponse => {
apiResponse.next = nextFunc(url, options, data);
apiResponse.data = data;
apiResponse.resource = resource ? data[resource] : null;
return apiResponse;
}
)
.catch(() => Promise.resolve(apiResponse));
}
);
}
Expand Down

0 comments on commit f4c2e49

Please sign in to comment.