* API: report failed Ajax requests to user incl. a hint that server error-log should contain more information

This commit is contained in:
Ralf Becker 2014-11-21 16:18:29 +00:00
parent 8b2a51b89f
commit 10b106619a
4 changed files with 33 additions and 9 deletions

View File

@ -33,6 +33,14 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
/** /**
* Internal implementation of the JSON request object. * Internal implementation of the JSON request object.
*
* @param {string} _menuaction
* @param {array} _parameters
* @param {function} _callback
* @param {object} _context
* @param {boolean} _async
* @param {object} _sender
* @param {egw} _egw
*/ */
function json_request(_menuaction, _parameters, _callback, _context, function json_request(_menuaction, _parameters, _callback, _context,
_async, _sender, _egw) _async, _sender, _egw)
@ -69,7 +77,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
/** /**
* Sends the assembled request to the server * Sends the assembled request to the server
* @param {boolean} [async=false] Overrides async provided in constructor to give an easy way to make simple async requests * @param {boolean} [async=false] Overrides async provided in constructor to give an easy way to make simple async requests
* @param {string} method='POST' allow to eg. use a (cachable) 'GET' request instead of POST * @param {string} method ='POST' allow to eg. use a (cachable) 'GET' request instead of POST
* *
* @return {jqXHR} jQuery jqXHR request object * @return {jqXHR} jQuery jqXHR request object
*/ */
@ -103,13 +111,18 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
// Don't error about an abort // Don't error about an abort
if(_err !== 'abort') if(_err !== 'abort')
{ {
this.egw.debug('error', 'Ajax request to', this.url, ' failed:', _err); this.egw.message.call(this.egw, this.egw.lang('Ajax request failed')+': '+_xmlhttp.statusText+' ('+_xmlhttp.status+
")\n\n"+this.egw.lang('Server error log should contain more information about the problem.')+
"\n"+this.egw.lang('Trying it again will usually not help!')+
"\n\nURL: "+this.url+"\n"+_xmlhttp.getAllResponseHeaders().match(/^Date:.*$/m)[0]);
this.egw.debug('error', 'Ajax request to', this.url, ' failed: ', _err, _xmlhttp.status, _xmlhttp.statusText);
} }
} }
}); });
return this.request; return this.request;
} };
json_request.prototype.handleResponse = function(data) { json_request.prototype.handleResponse = function(data) {
if (data && typeof data.response != 'undefined') if (data && typeof data.response != 'undefined')
@ -162,8 +175,10 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
); );
} catch(e) { } catch(e) {
var msg = e.message ? e.message : e + ''; var msg = e.message ? e.message : e + '';
var stack = e.stack ? "\n-- Stack trace --\n" + e.stack : "" var stack = e.stack ? "\n-- Stack trace --\n" + e.stack : "";
this.egw.debug('error', 'Exception "' + msg + '" while handling JSON response from ' + this.url + ' [' + JSON.stringify(this.parameters) + '] type "' + res.type + '", plugin', plugin, 'response', res, stack); this.egw.debug('error', 'Exception "' + msg + '" while handling JSON response from ' +
this.url + ' [' + JSON.stringify(this.parameters) + '] type "' + res.type +
'", plugin', plugin, 'response', res, stack);
} }
} }
} }
@ -175,7 +190,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
} }
} }
this.request = null; this.request = null;
} };
var json = { var json = {
@ -228,7 +243,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
// Add the entry // Add the entry
plugins[_type].push({ plugins[_type].push({
'callback': _callback, 'callback': _callback,
'context': _context, 'context': _context
}); });
}, },
@ -273,7 +288,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
{ {
req.alertHandler( req.alertHandler(
res.data.message, res.data.message,
res.data.details) res.data.details);
return true; return true;
} }
throw 'Invalid parameters'; throw 'Invalid parameters';
@ -326,7 +341,7 @@ egw.extend('json', egw.MODULE_WND_LOCAL, function(_app, _wnd) {
catch (e) catch (e)
{ {
req.egw.debug('error', 'Error while executing script: ', req.egw.debug('error', 'Error while executing script: ',
res.data,e) res.data,e);
} }
return true; return true;
} }

View File

@ -129,6 +129,9 @@ egw.extend('message', egw.MODULE_WND_LOCAL, function(_app, _wnd)
.text(matches[2])); .text(matches[2]));
msg_div.append(jQuery(_wnd.document.createElement('span')).text(parts[1])); msg_div.append(jQuery(_wnd.document.createElement('span')).text(parts[1]));
} }
// center the message
msg_div.css('right', ((jQuery(_wnd).innerWidth()-msg_div.width())/2)+'px');
if (_type == 'success') // clear message again after some time, if no error if (_type == 'success') // clear message again after some time, if no error
{ {
message_timer = _wnd.setTimeout(function() { message_timer = _wnd.setTimeout(function() {

View File

@ -55,6 +55,7 @@ addressbooks to sync in addition to personal addressbook groupdav de Adressbüch
admin common de Admin admin common de Admin
administration common de Administration administration common de Administration
afghanistan common de AFGHANISTAN afghanistan common de AFGHANISTAN
ajax request failed common de Ajax Anfrage fehlgeschlagen
albania common de ALBANIEN albania common de ALBANIEN
algeria common de ALGERIEN algeria common de ALGERIEN
all common de alle all common de alle
@ -724,6 +725,7 @@ serbia common de SERBIEN
server %1 has been added common de Server %1 wurde zugefügt server %1 has been added common de Server %1 wurde zugefügt
server answered. processing response... common de Server antwortet. Bearbeite Antwort... server answered. processing response... common de Server antwortet. Bearbeite Antwort...
server contacted. waiting for response... common de Server kontaktiert. Warte auf Antwort... server contacted. waiting for response... common de Server kontaktiert. Warte auf Antwort...
server error log should contain more information about the problem. common de Das Fehlerprotokoll des Servers sollte mehr Informationen über das Problem enthalten.
server is unwilling to perform. common de Server ist zur Ausführung nicht bereit. server is unwilling to perform. common de Server ist zur Ausführung nicht bereit.
server name common de Server Name server name common de Server Name
session has been killed common de Session wurde beendet session has been killed common de Session wurde beendet
@ -826,6 +828,7 @@ top common de Oben
total common de Gesamt total common de Gesamt
transparant bg for the icons? common de Transparenter Hintergrund für Symbole transparant bg for the icons? common de Transparenter Hintergrund für Symbole
trinidad and tobago common de TRINIDAD AND TOBAGO trinidad and tobago common de TRINIDAD AND TOBAGO
trying it again will usually not help! common de Es nochmal zu versuchen hilft im Allgemeinen nicht!
tuesday common de Dienstag tuesday common de Dienstag
tunisia common de TUNISIEN tunisia common de TUNISIEN
turkey common de TÜRKEI turkey common de TÜRKEI

View File

@ -55,6 +55,7 @@ addressbooks to sync in addition to personal addressbook groupdav en Addressbook
admin common en Admin admin common en Admin
administration common en Administration administration common en Administration
afghanistan common en AFGHANISTAN afghanistan common en AFGHANISTAN
ajax request failed common en Ajax request failed
albania common en ALBANIA albania common en ALBANIA
algeria common en ALGERIA algeria common en ALGERIA
all common en All all common en All
@ -724,6 +725,7 @@ serbia common en Serbia
server %1 has been added common en Server %1 has been added. server %1 has been added common en Server %1 has been added.
server answered. processing response... common en Server answered. Processing response... server answered. processing response... common en Server answered. Processing response...
server contacted. waiting for response... common en Server contacted. Waiting for response... server contacted. waiting for response... common en Server contacted. Waiting for response...
server error log should contain more information about the problem. common en Server error log should contain more information about the problem.
server is unwilling to perform. common en Server is unwilling to perform. server is unwilling to perform. common en Server is unwilling to perform.
server name common en Server name server name common en Server name
session has been killed common en Session has been killed. session has been killed common en Session has been killed.
@ -826,6 +828,7 @@ top common en Top
total common en Total total common en Total
transparant bg for the icons? common en Transparant bg for the icons transparant bg for the icons? common en Transparant bg for the icons
trinidad and tobago common en TRINIDAD AND TOBAGO trinidad and tobago common en TRINIDAD AND TOBAGO
trying it again will usually not help! common en Trying it again will usually not help!
tuesday common en Tuesday tuesday common en Tuesday
tunisia common en TUNISIA tunisia common en TUNISIA
turkey common en TURKEY turkey common en TURKEY