mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-07 06:36:55 +02:00
Consider 201 http status as a success
This commit is contained in:
@@ -39,6 +39,9 @@ if ((typeof Tomahawk === "undefined") || (Tomahawk === null)) {
|
|||||||
|
|
||||||
Tomahawk.apiVersion = "0.2.2";
|
Tomahawk.apiVersion = "0.2.2";
|
||||||
|
|
||||||
|
//Statuses considered a success for HTTP request
|
||||||
|
var httpSuccessStatuses = [200, 201];
|
||||||
|
|
||||||
// install RSVP.Promise as global Promise
|
// install RSVP.Promise as global Promise
|
||||||
if(window.Promise === undefined) {
|
if(window.Promise === undefined) {
|
||||||
window.Promise = window.RSVP.Promise;
|
window.Promise = window.RSVP.Promise;
|
||||||
@@ -337,7 +340,7 @@ Tomahawk.syncRequest = function (url, extraHeaders, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
xmlHttpRequest.send(null);
|
xmlHttpRequest.send(null);
|
||||||
if (xmlHttpRequest.status == 200) {
|
if (httpSuccessStatuses.indexOf(xmlHttpRequest.status) != -1) {
|
||||||
return xmlHttpRequest.responseText;
|
return xmlHttpRequest.responseText;
|
||||||
} else {
|
} else {
|
||||||
Tomahawk.log("Failed to do GET request: to: " + url);
|
Tomahawk.log("Failed to do GET request: to: " + url);
|
||||||
@@ -426,7 +429,7 @@ Tomahawk.nativeAsyncRequestDone = function (reqId, xhr) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Call the real callback
|
// Call the real callback
|
||||||
if (xhr.readyState == 4 && xhr.status == 200) {
|
if (xhr.readyState == 4 && httpSuccessStatuses.indexOf(xhr.status) != -1) {
|
||||||
// Call the real callback
|
// Call the real callback
|
||||||
if (Tomahawk.asyncRequestCallbacks[reqId].callback) {
|
if (Tomahawk.asyncRequestCallbacks[reqId].callback) {
|
||||||
Tomahawk.asyncRequestCallbacks[reqId].callback(xhr);
|
Tomahawk.asyncRequestCallbacks[reqId].callback(xhr);
|
||||||
@@ -477,7 +480,7 @@ Tomahawk.asyncRequest = function (url, callback, extraHeaders, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
xmlHttpRequest.onreadystatechange = function () {
|
xmlHttpRequest.onreadystatechange = function () {
|
||||||
if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
|
if (xmlHttpRequest.readyState == 4 && httpSuccessStatuses.indexOf(xmlHttpRequest.status) != -1) {
|
||||||
callback.call(window, xmlHttpRequest);
|
callback.call(window, xmlHttpRequest);
|
||||||
} else if (xmlHttpRequest.readyState === 4) {
|
} else if (xmlHttpRequest.readyState === 4) {
|
||||||
Tomahawk.log("Failed to do " + method + " request: to: " + url);
|
Tomahawk.log("Failed to do " + method + " request: to: " + url);
|
||||||
|
Reference in New Issue
Block a user