Skip to content

Commit

Permalink
Improved promise chain
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardonunesdev committed Sep 30, 2017
1 parent d4a3b52 commit 6015e37
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions domain-ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ const requestUrl = (url) => {

const requestDomain = (domain) => {
return new Promise((resolve, reject) => {
requestUrl('http://'+domain)
requestUrl('http://' + domain)
.then(resolve)
.catch((error) => {
requestUrl('https://'+domain)
.then(resolve)
.catch(reject);
return requestUrl('https://' + domain);
})
.then(resolve)
.catch(reject);
});
};

Expand All @@ -71,10 +71,9 @@ const domainPing = (domain) => {
return requestDomain(domain);
})
.then((statusCode) => {
data.success = true;
data.online = (statusCode === 200);
data.statusCode = statusCode;

data.success = true;
return resolve(data);
})
.catch((error) => {
Expand Down

0 comments on commit 6015e37

Please sign in to comment.