requests, errors, dialogs

This commit is contained in:
Rolux 2010-01-31 15:36:52 +05:30
parent 06852ed89c
commit c9f854061c
2 changed files with 18 additions and 13 deletions

View file

@ -97,6 +97,8 @@ Dialog
top: 24px; top: 24px;
height: 100%; height: 100%;
padding: 16px; padding: 16px;
font-size: 12px;
line-height: 16px;
} }
.OxDialog > .OxButtonsBar { .OxDialog > .OxButtonsBar {

View file

@ -443,9 +443,9 @@ requires
data: options.data data: options.data
}); });
function callback(data, callback) { function callback(data) {
delete requests[options.id]; delete requests[options.id];
callback(data); options.callback(data);
} }
function debug(request) { function debug(request) {
@ -476,20 +476,21 @@ requires
} }
function error(request, status, error) { function error(request, status, error) {
var result; var data;
console.log("error", request, status, error); Ox.print("error", request, status, error);
try { try {
result = JSON.parse(request.responseText); data = JSON.parse(request.responseText);
} catch(e) { } catch (error) {
result = { data = {
status: { status: {
code: request.status, code: request.status,
text: request.statusText text: request.statusText
} }
}; };
} }
options.callback(result); if (data.status.code < 500) {
if (result.status.code >= 500) { callback(data);
} else {
var $dialog = new Ox.Dialog({ var $dialog = new Ox.Dialog({
title: "Application Error", title: "Application Error",
buttons: [ buttons: [
@ -504,14 +505,16 @@ requires
{ {
value: "Close", value: "Close",
click: function() { click: function() {
$dialog.close(); $dialog.close(function() {
callback(data);
});
} }
} }
], ],
width: 400, width: 400,
height: 100 height: 100
}) })
.append(request.status + " " + request.statusText) .append("Sorry, we have encountered an application error while handling your request. To help us find out what went wrong, you may want to report this error to an administrator. Otherwise, please try again later.")
.open(); .open();
Ox.print({ Ox.print({
request: request, request: request,
@ -540,7 +543,7 @@ requires
data: data, data: data,
time: Ox.getTime() time: Ox.getTime()
}; };
callback(data, options.callback); callback(data);
} }
if (pending[options.id]) { if (pending[options.id]) {
@ -554,7 +557,7 @@ requires
}; };
if (cache[req] && (options.age == -1 || options.age > Ox.getTime() - cache[req].time)) { if (cache[req] && (options.age == -1 || options.age > Ox.getTime() - cache[req].time)) {
setTimeout(function() { setTimeout(function() {
callback(cache[req].data, callback); callback(cache[req].data);
}, 0); }, 0);
} else { } else {
pending[options.id] = true; pending[options.id] = true;