Last active
April 8, 2019 19:12
-
-
Save hunted-down-developer/24c614efb41e9179f41e653032e492a5 to your computer and use it in GitHub Desktop.
Request (GET) wrapped numa promise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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