3 function fetch_url(url
) {
4 return new Promise(function(resolve
, reject
) {
5 var request
= new XMLHttpRequest();
6 request
.addEventListener('load', function(event
) {
7 if (request
.status
== 200)
8 resolve(request
.response
);
10 reject(new Error('fetch_url: ' + request
.statusText
+ " : " + url
));
12 request
.addEventListener('error', function(event
) {
13 reject(new Error('fetch_url encountered an error: ' + url
));
15 request
.addEventListener('abort', function(event
) {
16 reject(new Error('fetch_url was aborted: ' + url
));
18 request
.open('GET', url
);