Skip to content

Commit 5a07f6b

Browse files
skydiverluiguild
andauthored
Release v3.1.1 (#112)
* fix JSON parse error when device is offline (#111) * add 503 error and fix makeRequest mixin when device is Offline or Service is unavailable * add 503 error and fix makeRequest mixin when device is Offline or Service is unavailable * version bump Co-authored-by: Luigui Delyer <git@s1x.com.br>
1 parent 381c344 commit 5a07f6b

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ewelink-api",
3-
"version": "3.1.0",
3+
"version": "3.1.1",
44
"description": "eWeLink API for Node.js",
55
"author": "Martín M.",
66
"license": "MIT",

src/data/errors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const errors = {
55
403: 'Forbidden',
66
404: 'Device does not exist',
77
406: 'Authentication failed',
8+
503: 'Service Temporarily Unavailable or Device is offline'
89
};
910

1011
const customErrors = {

src/mixins/makeRequest.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,13 @@ module.exports = {
4242
const requestUrl = `${apiUrl}${uri}${queryString}`;
4343

4444
const request = await fetch(requestUrl, payload);
45-
const response = await request.json();
46-
47-
const error = _get(response, 'error', false);
4845

49-
if (error) {
50-
return { error, msg: errors[error] };
46+
if (!request.ok) {
47+
return { error: request.status, msg: errors[request.status] };
5148
}
5249

53-
return response;
50+
const response = await request.json();
51+
52+
return response
5453
},
5554
};

0 commit comments

Comments
 (0)