Skip to content

Commit

Permalink
use Promise instead of async/await
Browse files Browse the repository at this point in the history
  • Loading branch information
moesoha committed Aug 23, 2017
1 parent f722238 commit 6f29744
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 20 deletions.
50 changes: 31 additions & 19 deletions lib/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,41 @@ Token.prototype.newClient = function () {
}));
};

Token.prototype.validate = async function (token) {
var response, code;
try {
response = await axiosInstance.request({
Token.prototype.validate = function (token) {
return (new Promise(function (resolve, reject) {
var response, code;
response = axiosInstance.request({
url: 'token/validate/' + token,
method: 'get',
responseType: 'text'
});
code = (response.response) ? response.response.status : response.status;
} catch (response) {
code = (response.response) ? response.response.status : null;
}

switch (code) {
case 204:
return (true);
break;
case 418:
return (false);
break;
default:
throw new Error("Unknown status code when validating token.");
}
response.then(function (response) {
code = (response.response) ? response.response.status : response.status;
switch (code) {
case 204:
resolve(true);
break;
case 418:
resolve(false);
break;
default:
reject("Unknown status code when validating token.");
}
});
response.catch(function (response) {
code = (response.response) ? response.response.status : null;
switch (code) {
case 204:
resolve(true);
break;
case 418:
resolve(false);
break;
default:
reject("Unknown status code when validating token.");
}
});
}));
}

module.exports = Token;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oiinhand-sdk-axios",
"version": "1.0.8",
"version": "1.0.9",
"description": "The Node.js SDK for OI in Hand API",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 6f29744

Please sign in to comment.