front-end error handling

This commit is contained in:
Davide Alberani 2018-12-12 21:14:00 +01:00
parent d9740938b9
commit 3f31fbe67d
2 changed files with 17 additions and 5 deletions

View file

@ -75,12 +75,24 @@ function sendData(data) {
msg = "something went wrong sending the data: " + response.status; msg = "something went wrong sending the data: " + response.status;
console.log(msg); console.log(msg);
M.toast({"html": msg}); M.toast({"html": msg});
}
cancelPhoto();
return response.json();
}).then(function(json) {
json = json || {};
console.log(json);
if (json && json.success) {
msg = "❤ ❤ ❤ photo sent successfully! ❤ ❤ ❤";
console.log(msg);
M.toast({"html": msg});
} else { } else {
msg = "photo was sent successfully!"; msg = "something wrong on the backend";
console.log(msg);
M.toast({"html": msg});
msg = "the server says: " + json.message;
console.log(msg); console.log(msg);
M.toast({"html": msg}); M.toast({"html": msg});
} }
cancelPhoto();
}).catch(function(err) { }).catch(function(err) {
msg = "something went wrong connecting to server: " + err; msg = "something went wrong connecting to server: " + err;
console.log(msg); console.log(msg);

View file

@ -91,7 +91,7 @@ class BaseException(Exception):
:type message: str :type message: str
:param status: numeric http status code :param status: numeric http status code
:type status: int""" :type status: int"""
def __init__(self, message, status=400): def __init__(self, message, status=200):
super(BaseException, self).__init__(message) super(BaseException, self).__init__(message)
self.message = message self.message = message
self.status = status self.status = status
@ -136,7 +136,7 @@ class BaseHandler(tornado.web.RequestHandler):
for key, value in kwargs.items(): for key, value in kwargs.items():
setattr(self, key, value) setattr(self, key, value)
def build_error(self, message='', status=400): def build_error(self, message='', status=200):
"""Build and write an error message. """Build and write an error message.
:param message: textual message :param message: textual message
@ -145,7 +145,7 @@ class BaseHandler(tornado.web.RequestHandler):
:type status: int :type status: int
""" """
self.set_status(status) self.set_status(status)
self.write({'error': True, 'message': message}) self.write({'success': False, 'message': message})
class RootHandler(BaseHandler): class RootHandler(BaseHandler):