Skip to content

Commit

Permalink
isInvalidHttpEndpoint added to HttpProvider for a better readability
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Furter committed Feb 26, 2019
1 parent 46f3017 commit bed7b7e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/web3-providers/src/providers/HttpProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export default class HttpProvider {
}
}

if (request.response === null && request.status === 0) {
if (this.isInvalidHttpEndpoint(request)) {
reject(new Error(`Connection refused or URL couldn't be resolved: ${this.host}`));
}
}
Expand All @@ -176,4 +176,17 @@ export default class HttpProvider {
}
});
}

/**
* Checks if the error `net::ERR_NAME_NOT_RESOLVED` or `net::ERR_CONNECTION_REFUSED` will appear.
*
* @method isInvalidHttpEndpoint
*
* @param {Object} request
*
* @returns {Boolean}
*/
isInvalidHttpEndpoint(request) {
return request.response === null && request.status === 0;
}
}

0 comments on commit bed7b7e

Please sign in to comment.