Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
properly addes a default onFailure method to all Requests
Browse files Browse the repository at this point in the history
fixes Bug 733639 - Unable to add Vold Utils and Menuitems libraries into an addon.
  • Loading branch information
seanmonstar committed Mar 8, 2012
1 parent d47c9ec commit 3ec1e71
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions media/base/js/flightdeck/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@
var Request = require('shipyard/http/Request'),
Cookie = require('shipyard/utils/Cookie'),
log = require('shipyard/utils/log'),
dom = require('shipyard/dom'),

fd = dom.window.get('fd');
dom = require('shipyard/dom');

function fd() {
return dom.window.get('fd');
}

Request.prototype.options.headers['X-CSRFToken'] = Cookie.read('csrftoken');

Request.prototype.options.onFailure = function(text) {
var oldInit = Request.prototype.initialize;
var defaultFailure = function(text) {
if (this.status !== 0 && text) {
var response;
try {
response = JSON.parse(text);
} catch (notJSON) {
log.warn('Response error is not valid JSON', text);
log.warn('Response error is not valid JSON');
if (text.indexOf('<html') !== -1) {
// We somehow got a full HTML page. Bad!
log.error('Response is an HTML page!');
Expand All @@ -26,6 +29,16 @@ Request.prototype.options.onFailure = function(text) {
}
}

fd.error.alert(this.xhr.statusText, response);
fd().error.alert(this.xhr.statusText, response);
}
};

Request.implement('initialize', function FD_Request(options) {
if (!options) {
options = {};
}
if (!options.onFailure) {
options.onFailure = defaultFailure;
}
oldInit.call(this, options);
});

0 comments on commit 3ec1e71

Please sign in to comment.