From b2efe0bbbbe5aca31a268882795cd6f67c6c6012 Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Thu, 19 Nov 2009 16:33:03 +0000 Subject: [PATCH] Added error-reporting for the case where a HTTP response is 200 OK but it does not contain any XML (for example because it is a human-readable HTML page explaining what went wrong). Removed obsolete CVS Id. --- js/pz2.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/js/pz2.js b/js/pz2.js index affff33..3804d1a 100644 --- a/js/pz2.js +++ b/js/pz2.js @@ -1,5 +1,4 @@ /* -** $Id: pz2.js,v 1.70 2008-03-12 11:36:57 jakub Exp $ ** pz2.js - pazpar2's javascript client library. */ @@ -750,7 +749,7 @@ pzHttpRequest.prototype = for (var key in this.requestHeaders) this.request.setRequestHeader(key, this.requestHeaders[key]); this.request.onreadystatechange = function () { - context._handleResponse(); + context._handleResponse(url); /// url used ONLY for error reporting } this.request.send(data); }, @@ -763,7 +762,7 @@ pzHttpRequest.prototype = return this.url; }, - _handleResponse: function () + _handleResponse: function (savedUrlForErrorReporting) { if ( this.request.readyState == 4 ) { // pick up appplication errors first @@ -786,6 +785,16 @@ pzHttpRequest.prototype = else { throw err; } + } else if (this.request.status == 200 && + this.request.responseXML == null) { + var err = new Error("XML response is empty but no error " + + "for " + savedUrlForErrorReporting); + err.code = -1; + if (this.errorHandler) { + this.errorHandler(err); + } else { + throw err; + } } else if (this.request.status == 200) { this.callback(this.request.responseXML); } else { -- 1.7.10.4