Skip to content
This repository was archived by the owner on Sep 1, 2022. It is now read-only.

Commit 37cacfc

Browse files
committed
fix(request): correct errors handling
1 parent 4d451e5 commit 37cacfc

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,25 @@
6161
"@types/js-cookie": "^2.1.0",
6262
"@types/qs": "^6.5.1",
6363
"@types/sinon": "^5.0.1",
64-
"ava": "^1.0.0-beta.4",
64+
"ava": "^1.0.0-beta.8",
6565
"browser-env": "^3.2.5",
66-
"codecov": "^3.0.2",
66+
"codecov": "^3.0.4",
6767
"cz-conventional-changelog": "^2.1.0",
6868
"form-data": "^2.3.2",
69-
"gh-pages": "^1.0.0",
69+
"gh-pages": "^1.2.0",
7070
"npm-run-all": "^4.1.3",
71-
"npm-scripts-info": "^0.3.6",
71+
"npm-scripts-info": "^0.3.9",
7272
"nsp": "^3.2.1",
73-
"nyc": "^12.0.1",
73+
"nyc": "^13.0.1",
7474
"opn-cli": "^3.1.0",
75-
"prettier": "^1.12.1",
75+
"prettier": "^1.14.2",
7676
"sinon": "^6.0.0",
7777
"standard-version": "^4.4.0",
7878
"trash-cli": "^1.4.0",
79-
"tslint": "^5.10.0",
80-
"tslint-config-prettier": "^1.13.0",
81-
"typedoc": "^0.11.1",
82-
"typescript": "^2.8.3"
79+
"tslint": "^5.11.0",
80+
"tslint-config-prettier": "^1.15.0",
81+
"typedoc": "^0.12.0",
82+
"typescript": "^3.0.3"
8383
},
8484
"ava": {
8585
"failFast": true,

src/lib/sdk.spec.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,15 +133,9 @@ test('Make a request with custom axios config', t => {
133133
});
134134

135135
test('Catch a request', async t => {
136-
t.context.axiosRequest.rejects({
137-
response: {
138-
data: {
139-
message: 'error'
140-
}
141-
}
142-
});
136+
t.context.axiosRequest.rejects(new Error('error'));
143137

144-
await t.throws(
138+
await t.throwsAsync(
145139
async () => {
146140
await t.context.strapi.request('get', '/foo');
147141
},

src/lib/sdk.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,11 @@ export default class Strapi {
9595
});
9696
return response.data;
9797
} catch (error) {
98-
throw new Error(error.response.data.message);
98+
if (error.response) {
99+
throw new Error(error.response.data.message);
100+
} else {
101+
throw error;
102+
}
99103
}
100104
}
101105

0 commit comments

Comments
 (0)