background_scripts/bgscript-xhrs.js
// A generic XHR request code, requires an HTTP XML request method, a request url, and an access token.
A generic XHR request code, requires an HTTP XML request method, a request url, and an access token.
A generic XHR request code requires an HTTP XML request method a request url and an access token .
function makeXhrRequestGeneric(method, url, token) {
	return new Promise((resolve, reject) => {
		let xhr = new XMLHttpRequest();
		xhr.open(method, url, true);
		xhr.setRequestHeader("Authorization", "Bearer " + token);
		xhr.onload = function() {
			if (xhr.status >= 200 && xhr.status < 300) {
				return resolve(xhr.response);
			} else {
				reject(
					Error({
						status: xhr.status,
						statusTextInElse: xhr.statusText
					})
				);
			}
		};
		xhr.onerror = function() {
			reject(
				Error({
					status: xhr.status,
					statusText: xhr.statusText
				})
			);
		};
		xhr.send();
	});
}
function makeXhrRequestGeneric ( method , url , token ) { return new Promise ( ( resolve , reject ) => { let xhr = new XMLHttpRequest ( ) ; xhr . open ( method , url , true ) ; xhr . setRequestHeader ( "Authorization" , "Bearer " + token ) ; xhr . onload = function ( ) { if ( xhr . status >= 200 && xhr . status < 300 ) { return resolve ( xhr . response ) ; } else { reject ( Error ( { status : xhr . status , statusTextInElse : xhr . statusText } ) ) ; } } ; xhr . onerror = function ( ) { reject ( Error ( { status : xhr . status , statusText : xhr . statusText } ) ) ; } ; xhr . send ( ) ; } ) ; }
A generic XHR request code, requires an HTTP XML request method, a request url, and an access token.
A generic XHR request code requires an HTTP XML request method a request url and an access token .