Skip to content

Instantly share code, notes, and snippets.

@hunted-down-developer
Last active April 8, 2019 19:12
Show Gist options
  • Save hunted-down-developer/24c614efb41e9179f41e653032e492a5 to your computer and use it in GitHub Desktop.
Save hunted-down-developer/24c614efb41e9179f41e653032e492a5 to your computer and use it in GitHub Desktop.
Request (GET) wrapped numa promise
request(url){
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.onload = () => {
if(xhr.status >= 200 && xhr.status < 300){
resolve(xhr.response);
}else{
reject({
status: xhr.status,
statusText: xhr.statusText,
response: xhr.response
});
}
}
xhr.onerror = () => reject(xhr.response);
xhr.send();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment