summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-23 22:26:07 +0300
committerAndrew Dolgov <[email protected]>2021-02-23 22:26:07 +0300
commit8d2e3c2528e67f8650c122f014364a34bf690d2a (patch)
treefd44203c8a5919848f689cb6caa8c0c8d0784d54 /js
parent37d46411c77bda2b1823f7d230b06e36b7125a8d (diff)
drop errors.php and simplify error handling
Diffstat (limited to 'js')
-rw-r--r--js/App.js60
-rwxr-xr-xjs/common.js5
2 files changed, 25 insertions, 40 deletions
diff --git a/js/App.js b/js/App.js
index 68f3740c5..6cad062f0 100644
--- a/js/App.js
+++ b/js/App.js
@@ -407,23 +407,15 @@ const App = {
const counters = reply['counters'];
const runtime_info = reply['runtime-info'];
- if (error) {
- const code = error['code'];
-
- if (code && code != 0) {
- const msg = error['message'];
-
- console.warn("[handleRpcJson] received fatal error ", code, msg);
-
- /* global ERRORS */
- this.Error.fatal(ERRORS[code], {info: msg, code: code});
- return false;
- }
+ if (error && error.code && error.code != App.Error.E_SUCCESS) {
+ console.warn("handleRpcJson: fatal error", error);
+ this.Error.fatal(error.code);
+ return false;
}
if (seq && this.get_seq() != seq) {
- console.warn("[handleRpcJson] sequence mismatch: ", seq, '!=', this.get_seq());
- return;
+ console.warn("handleRpcJson: sequence mismatch: ", seq, '!=', this.get_seq());
+ return false;
}
// not in preferences
@@ -442,10 +434,13 @@ const App = {
if (netalert) netalert.hide();
+ return true;
} else {
if (netalert) netalert.show();
Notify.error("Communication problem with server.");
+
+ return false;
}
},
parseRuntimeInfo: function(data) {
@@ -487,20 +482,6 @@ const App = {
PluginHost.run(PluginHost.HOOK_RUNTIME_INFO_LOADED, data);
},
backendSanityCallback: function(reply) {
- if (!reply) {
- this.Error.fatal(ERRORS[3]);
- return;
- }
-
- if (reply['error']) {
- const code = reply['error']['code'];
-
- if (code && code != 0) {
- return this.Error.fatal(ERRORS[code],
- {code: code, info: reply['error']['message']});
- }
- }
-
console.log("sanity check ok");
const params = reply['init-params'];
@@ -547,24 +528,25 @@ const App = {
this.initSecondStage();
},
Error: {
+ E_SUCCESS: "E_SUCCESS",
+ E_UNAUTHORIZED: "E_UNAUTHORIZED",
+ E_SCHEMA_MISMATCH: "E_SCHEMA_MISMATCH",
fatal: function (error, params = {}) {
- if (params.code) {
- if (params.code == 6) {
- window.location.href = "index.php";
- return;
- } else if (params.code == 5) {
- window.location.href = "public.php?op=dbupdate";
- return;
- }
- }
+ if (error == App.Error.E_UNAUTHORIZED) {
+ window.location.href = "index.php";
+ return;
+ } else if (error == App.Error.E_SCHEMA_MISMATCH) {
+ window.location.href = "public.php?op=dbupdate";
+ return;
+ }
- return this.report(error,
+ return this.report(__("Fatal error: %s").replace("%s", error),
{...{title: __("Fatal error")}, ...params});
},
report: function(error, params = {}) {
if (!error) return;
- console.error("[Error.report]", error, params);
+ console.error("error.report:", error, params);
const message = params.message ? params.message : error.toString();
diff --git a/js/common.js b/js/common.js
index df1bf8690..670ee1b30 100755
--- a/js/common.js
+++ b/js/common.js
@@ -179,7 +179,10 @@ const xhr = {
console.log('xhr.json', '<<<', obj);
if (obj && typeof App != "undefined")
- App.handleRpcJson(obj);
+ if (!App.handleRpcJson(obj)) {
+ reject(obj);
+ return;
+ }
if (complete != undefined) complete(obj);