Start using sane HTTP codes in the API

master
Daniel Berteaud 10 years ago
parent 4e492de55a
commit d4db36765a
  1. 11
      public/js/vroom.js
  2. 28
      vroom.pl

@ -1638,21 +1638,22 @@ function initVroom(room) {
}) })
}, },
error: function(data) { error: function(data) {
data = data.responseJSON;
if (data.msg){
$.notify(data.msg, 'error');
}
else{
$.notify(locale.ERROR_OCCURRED, 'error'); $.notify(locale.ERROR_OCCURRED, 'error');
}
}, },
success: function(data) { success: function(data) {
$('#recipient').val(''); $('#recipient').val('');
if (data.status == 'success'){
$('#inviteModal').modal('hide'); $('#inviteModal').modal('hide');
$('#email-list-invite').find('.email-entry:not(:last)').remove(); $('#email-list-invite').find('.email-entry:not(:last)').remove();
$('#email-list-invite').find('input').val(''); $('#email-list-invite').find('input').val('');
$('#message').val(''); $('#message').val('');
$.notify(data.msg, 'success'); $.notify(data.msg, 'success');
} }
else{
$.notify(data.msg, 'error');
}
}
}); });
}); });

@ -1251,9 +1251,10 @@ any '/api' => sub {
return $self->render( return $self->render(
json => { json => {
status => 'error', status => 'error',
msg => 'UNSUPPORTED_LANG' msg => $self->l('UNSUPPORTED_LANG'),
err => 'UNSUPPORTED_LANG'
}, },
status => 503 status => 400
); );
} }
$self->session(language => $req->{param}->{language}); $self->session(language => $req->{param}->{language});
@ -1271,8 +1272,8 @@ any '/api' => sub {
param => $req->{param} param => $req->{param}
); );
# Here are mthod not tied to a room # Here are method not tied to a room
if ($req->{action} eq 'get_room_list'){ if ($res && $req->{action} eq 'get_room_list'){
my $rooms = $self->get_room_list; my $rooms = $self->get_room_list;
# Blank out a few param we don't need # Blank out a few param we don't need
foreach my $r (keys %{$rooms}){ foreach my $r (keys %{$rooms}){
@ -1293,9 +1294,10 @@ any '/api' => sub {
return $self->render( return $self->render(
json => { json => {
status => 'error', status => 'error',
msg => 'NOT_ALLOWED' msg => $self->l('NOT_ALLOWED'),
err => 'NOT_ALLOWED'
}, },
status => '403' status => '401'
); );
} }
# Ok, now, we don't have to bother with authorization anymore # Ok, now, we don't have to bother with authorization anymore
@ -1306,8 +1308,10 @@ any '/api' => sub {
return $self->render( return $self->render(
json => { json => {
status => 'error', status => 'error',
msg => $self->l('ERROR_MAIL_INVALID') msg => $self->l('ERROR_MAIL_INVALID'),
} err => 'ERROR_MAIL_INVALID'
},
status => 400
); );
} }
} }
@ -1330,8 +1334,10 @@ any '/api' => sub {
return $self->render( return $self->render(
json => { json => {
status => 'error', status => 'error',
msg => 'ERROR_OCCURRED' msg => $self->l('ERROR_OCCURRED'),
} err => 'ERROR_OCCURRED'
},
status => 400
); );
} }
$self->app->log->info("Email invitation to join room " . $req->{param}->{room} . " sent to " . $addr); $self->app->log->info("Email invitation to join room " . $req->{param}->{room} . " sent to " . $addr);
@ -1339,7 +1345,7 @@ any '/api' => sub {
return $self->render( return $self->render(
json => { json => {
status => 'success', status => 'success',
msg => sprintf($self->l('INVITE_SENT_TO_s'), join("\n", @$rcpts)) msg => sprintf($self->l('INVITE_SENT_TO_s'), join("\n", @$rcpts)),
} }
); );
} }

Loading…
Cancel
Save