front-end error handling
This commit is contained in:
parent
d9740938b9
commit
3f31fbe67d
2 changed files with 17 additions and 5 deletions
|
@ -75,12 +75,24 @@ function sendData(data) {
|
|||
msg = "something went wrong sending the data: " + response.status;
|
||||
console.log(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 {
|
||||
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);
|
||||
M.toast({"html": msg});
|
||||
}
|
||||
cancelPhoto();
|
||||
}).catch(function(err) {
|
||||
msg = "something went wrong connecting to server: " + err;
|
||||
console.log(msg);
|
||||
|
|
|
@ -91,7 +91,7 @@ class BaseException(Exception):
|
|||
:type message: str
|
||||
:param status: numeric http status code
|
||||
:type status: int"""
|
||||
def __init__(self, message, status=400):
|
||||
def __init__(self, message, status=200):
|
||||
super(BaseException, self).__init__(message)
|
||||
self.message = message
|
||||
self.status = status
|
||||
|
@ -136,7 +136,7 @@ class BaseHandler(tornado.web.RequestHandler):
|
|||
for key, value in kwargs.items():
|
||||
setattr(self, key, value)
|
||||
|
||||
def build_error(self, message='', status=400):
|
||||
def build_error(self, message='', status=200):
|
||||
"""Build and write an error message.
|
||||
|
||||
:param message: textual message
|
||||
|
@ -145,7 +145,7 @@ class BaseHandler(tornado.web.RequestHandler):
|
|||
:type status: int
|
||||
"""
|
||||
self.set_status(status)
|
||||
self.write({'error': True, 'message': message})
|
||||
self.write({'success': False, 'message': message})
|
||||
|
||||
|
||||
class RootHandler(BaseHandler):
|
||||
|
|
Loading…
Reference in a new issue