Skip to content

Commit

Permalink
pz2.js: also pass the request to the error handler
Browse files Browse the repository at this point in the history
without that, you’d have to rely on »this« to be the pz2 object (to get its »request« property) meaning you couldn’t access the request and your own object’s properties at the same time while error handling
  • Loading branch information
ssp committed Mar 6, 2014
1 parent 42d2e69 commit bd86ad8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pz2.js
Expand Up @@ -1001,7 +1001,7 @@ pzHttpRequest.prototype =
err = new Error(errorMessage + errorInformation);
err.code = errorCode;
if (this.errorHandler) {
this.errorHandler(err);
this.errorHandler(err, this.request);
}
else {
throw err;
Expand Down
2 changes: 1 addition & 1 deletion src/parts/init.js
Expand Up @@ -86,7 +86,7 @@ pz2_client.prototype.initialiseService = function () {
showtime: 1000, //each timer (show, stat, term, bytarget) can be specified this way
onbytarget: jQuery.proxy(this.onbytarget, this),
onstat: jQuery.proxy(this.onstat, this),
errorhandler: jQuery.proxy(this.onerror, null, this),
errorhandler: jQuery.proxy(this.onerror, this),
showResponseType: ''
};

Expand Down
30 changes: 15 additions & 15 deletions src/parts/status.js
Expand Up @@ -161,43 +161,43 @@ pz2_client.prototype.onstat = function (data) {


/**
* @param {object} that - pz2_client
* @param {object} error
* @param {XMLHttpRequest} request
* @returns {undefined}
*/
pz2_client.prototype.onerror = function (that, error) {
that.errorCount++;
pz2_client.prototype.onerror = function (error, request) {
this.errorCount++;
var errorCode = parseInt(error.code, 10);

if (errorCode !== 12 && that.errorCount < 3 && this.request.status < 500) {
if (errorCode === 1 && this.request.status === 417) {
if (errorCode !== 12 && this.errorCount < 3 && request.status < 500) {
if (errorCode === 1 && request.status === 417) {
// The pazpar2 session has expired: create a new one.
that.initialisePazpar2();
this.initialisePazpar2();
}
else if (errorCode === 100 && this.request.status === 417) {
else if (errorCode === 100 && request.status === 417) {
// The Service Proxy session has expired / cookie got lost: create a new one.
that.initialiseServiceProxy();
this.initialiseServiceProxy();
}
}
else {
// The service is unavailable: Disable the search form.
var jRecordCount = jQuery('.pz2-recordCount');
jRecordCount.empty();
var message = that.localise('Suche momentan nicht verfügbar.', 'status');
var message = this.localise('Suche momentan nicht verfügbar.', 'status');
jRecordCount.text(message);
jRecordCount.addClass('pz2-noResults');

if (that.pz2InitTimeout !== undefined) {
clearTimeout(that.pz2InitTimeout);
if (this.pz2InitTimeout !== undefined) {
clearTimeout(this.pz2InitTimeout);
}

that.pz2InitTimeout = setTimeout(jQuery.proxy(that.initialiseService, that), 15000);
that.errorCount = 0;
this.pz2InitTimeout = setTimeout(jQuery.proxy(this.initialiseService, this), 15000);
this.errorCount = 0;
}

// If the error happens while loading, clear the current search term,
// to allow restarting the search.
if (that.my_paz.activeClients > 0) {
that.currentView.query = null;
if (this.my_paz.activeClients > 0) {
this.currentView.query = null;
}
};

0 comments on commit bd86ad8

Please sign in to comment.