1
0
mirror of https://github.com/dani/vroom.git synced 2024-06-02 05:21:39 +02:00

Cleanup error handling in ajax requests

This commit is contained in:
Daniel Berteaud 2014-05-14 13:52:36 +02:00
parent fdff058521
commit 2800c35dca
2 changed files with 26 additions and 27 deletions

View File

@ -528,12 +528,16 @@ function initVroom(room) {
room: roomName
},
error: function(data) {
var msg = (data && data.msg) ? data.msg : locale.ERROR_OCCURED;
$.notify(msg, 'error');
$.notify(locale.ERROR_OCCURED, 'error');
},
success: function(data) {
$.notify(data.msg, 'success');
$('#recipient,#message').val('');
if (data.status == 'success'){
$.notify(data.msg, 'success');
}
else{
$.notify(data.msg, 'error');
}
}
});
});
@ -653,8 +657,7 @@ function initVroom(room) {
room: roomName
},
error: function(data) {
var msg = locale.ERROR_OCCURED;
$.notify(msg, 'error');
$.notify(locale.ERROR_OCCURED, 'error');
},
success: function(data) {
$('#authPass').val('');
@ -694,8 +697,7 @@ function initVroom(room) {
room: roomName
},
error: function() {
var msg = locale.ERROR_OCCURED;
$.notify(msg, 'error');
$.notify(locale.ERROR_OCCURED, 'error');
},
success: function(data) {
$('#joinPass').val('');
@ -719,8 +721,7 @@ function initVroom(room) {
room: roomName
},
error: function() {
var msg = locale.ERROR_OCCURED;
$.notify(msg, 'error');
$.notify(locale.ERROR_OCCURED, 'error');
},
success: function(data) {
$('#joinPass').val('');
@ -757,8 +758,7 @@ function initVroom(room) {
room: roomName
},
error: function() {
var msg = locale.ERROR_OCCURED;
$.notify(msg, 'error');
$.notify(locale.ERROR_OCCURED, 'error');
},
success: function(data) {
$('#ownerPass').val('');
@ -782,8 +782,7 @@ function initVroom(room) {
room: roomName
},
error: function() {
var msg = locale.ERROR_OCCURED;
$.notify(msg, 'error');
$.notify(locale.ERROR_OCCURED, 'error');
},
success: function(data) {
$('#ownerPass').val('');
@ -901,12 +900,10 @@ function initVroom(room) {
room: roomName
},
error: function(data) {
var msg = (data && data.msg) ? data.msg : locale.ERROR_OCCURED;
$.notify(msg, 'error');
$.notify(locale.ERROR_OCCURED, 'error');
},
success: function(data) {
// In case of success, only notify if the server replied something
if (data.msg !== ''){
if (data.status == 'success' && data.msg && data.msg != ''){
$.notify(data.msg, 'success');
}
}

View File

@ -455,18 +455,18 @@ post '/action' => sub {
if (!$self->session('name') || !$self->has_joined($self->session('name'), $room) || !$self->session($room) || !$self->session($room)->{role}){
return $self->render(
json => {
msg => $self->l('ERROR_NOT_LOGGED_IN'),
msg => $self->l('ERROR_NOT_LOGGED_IN'),
status => 'error'
},
status => 403
);
}
$self->stash(room => $room);
my $data = $self->get_room($room);
return $self->render(
json => {
msg => sprintf ($self->l("ERROR_ROOM_s_DOESNT_EXIST"), $room)
msg => sprintf ($self->l("ERROR_ROOM_s_DOESNT_EXIST"), $room),
status => 'error'
},
status => '500'
) unless ($data);
if ($action eq 'invite'){
@ -485,14 +485,15 @@ post '/action' => sub {
) ||
return $self->render(
json => {
msg => $self->l('ERROR_OCCURED'),
msg => $self->l('ERROR_OCCURED'),
status => 'error'
},
status => 500
);
$self->app->log->info($self->session('name') . " sent an invitation for room $room to $rcpt");
$self->render(
json => {
msg => sprintf($self->l('INVITE_SENT_TO_s'), $rcpt)
msg => sprintf($self->l('INVITE_SENT_TO_s'), $rcpt),
status => 'success'
}
);
}
@ -505,15 +506,16 @@ post '/action' => sub {
if (!$res){
return $self->render(
json => {
msg => $self->l('ERROR_OCCURED'),
msg => $self->l('ERROR_OCCURED'),
status => 'error'
},
status => '500'
);
}
else{
return $self->render(
json => {
msg => '',
msg => '',
status => 'success'
}
);
}