aboutsummaryrefslogtreecommitdiff
path: root/web/app
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2015-12-20 21:36:16 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2015-12-20 21:36:16 +1300
commitf04d420b323a324233c48d525254f1211afc0771 (patch)
tree2c4e49bf9dea236dbc069391f57ec5e0b64032e4 /web/app
parent2bb63a0b1c82c42c0d13614c5a67521130165368 (diff)
downloadtraccar-server-f04d420b323a324233c48d525254f1211afc0771.tar.gz
traccar-server-f04d420b323a324233c48d525254f1211afc0771.tar.bz2
traccar-server-f04d420b323a324233c48d525254f1211afc0771.zip
Update javascript API error handling
Diffstat (limited to 'web/app')
-rw-r--r--web/app/Application.js30
-rw-r--r--web/app/ErrorManager.js44
-rw-r--r--web/app/view/BaseEditDialogController.js5
-rw-r--r--web/app/view/UserDialogController.js4
4 files changed, 11 insertions, 72 deletions
diff --git a/web/app/Application.js b/web/app/Application.js
index 5cc192686..fc4344a08 100644
--- a/web/app/Application.js
+++ b/web/app/Application.js
@@ -20,7 +20,6 @@ Ext.define('Traccar.Application', {
requires: [
'Traccar.Style',
- 'Traccar.ErrorManager',
'Traccar.AttributeFormatter'
],
@@ -79,33 +78,20 @@ Ext.define('Traccar.Application', {
},
showError: function (response) {
+ var data;
if (Ext.isString(response)) {
Ext.Msg.alert(Strings.errorTitle, response);
+ } else if (response.responseText) {
+ data = Ext.decode(response.responseText);
+ if (data.details) {
+ Ext.Msg.alert(Strings.errorTitle, data.details);
+ } else {
+ Ext.Msg.alert(Strings.errorTitle, data.message);
+ }
} else if (response.statusText) {
Ext.Msg.alert(Strings.errorTitle, response.statusText);
} else {
Ext.Msg.alert(Strings.errorTitle, Strings.errorConnection);
}
- },
-
- getErrorHandler: function (scope, handler) {
- return function (options, success, response) {
- var result;
- if (success) {
- result = Ext.decode(response.responseText);
- if (!result.success) {
- Ext.Msg.alert(Strings.errorTitle, result.error);
- }
- if (handler) {
- handler.call(scope, options, success, response);
- }
- } else {
- if (response.statusText) {
- Ext.Msg.alert(Strings.errorTitle, response.statusText);
- } else {
- Ext.Msg.alert(Strings.errorTitle, Strings.errorConnection);
- }
- }
- };
}
});
diff --git a/web/app/ErrorManager.js b/web/app/ErrorManager.js
deleted file mode 100644
index 50fa347c2..000000000
--- a/web/app/ErrorManager.js
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-Ext.define('Traccar.ErrorManager', {
- singleton: true,
-
- check: function (success, response) {
- var result;
- if (success) {
- result = Ext.decode(response.responseText);
- if (result.success || result.error === undefined) {
- return true;
- } else {
- Ext.Msg.alert(Strings.errorTitle, result.error);
- return false;
- }
- } else {
- if (response.statusText) {
- Ext.Msg.alert(Strings.errorTitle, response.statusText);
- } else {
- Ext.Msg.alert(Strings.errorTitle, response.status.toString()); // TODO: text message
- }
- return false;
- }
- },
-
- error: function (message) {
- Ext.Msg.alert(Strings.errorTitle, message);
- }
-
-});
diff --git a/web/app/view/BaseEditDialogController.js b/web/app/view/BaseEditDialogController.js
index 3b43cacf3..33bd01bd8 100644
--- a/web/app/view/BaseEditDialogController.js
+++ b/web/app/view/BaseEditDialogController.js
@@ -29,12 +29,9 @@ Ext.define('Traccar.view.BaseEditDialogController', {
store.add(record);
}
store.sync({
- success: function () {
- store.reload(); // workaround for selection problem
- },
failure: function (batch) {
store.rejectChanges();
- Traccar.ErrorManager.check(true, batch.exceptions[0].getResponse());
+ Traccar.app.showError(batch.exceptions[0].getError().response);
}
});
} else {
diff --git a/web/app/view/UserDialogController.js b/web/app/view/UserDialogController.js
index a5d045f5b..11f8c2f46 100644
--- a/web/app/view/UserDialogController.js
+++ b/web/app/view/UserDialogController.js
@@ -38,8 +38,8 @@ Ext.define('Traccar.view.UserDialogController', {
}
store.sync({
failure: function (batch) {
- store.rejectChanges(); // TODO
- Traccar.ErrorManager.check(true, batch.exceptions[0].getResponse());
+ store.rejectChanges();
+ Traccar.app.showError(batch.exceptions[0].getError().response);
}
});
}