From d4db36765abe44d12aa7f1ac61e98ada5e7994a9 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 4 Feb 2015 22:36:28 +0100 Subject: [PATCH] Start using sane HTTP codes in the API --- public/js/vroom.js | 23 ++++++++++++----------- vroom.pl | 28 +++++++++++++++++----------- 2 files changed, 29 insertions(+), 22 deletions(-) diff --git a/public/js/vroom.js b/public/js/vroom.js index 8fe817e..e7d38c8 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -1638,20 +1638,21 @@ function initVroom(room) { }) }, error: function(data) { - $.notify(locale.ERROR_OCCURRED, 'error'); - }, - success: function(data) { - $('#recipient').val(''); - if (data.status == 'success'){ - $('#inviteModal').modal('hide'); - $('#email-list-invite').find('.email-entry:not(:last)').remove(); - $('#email-list-invite').find('input').val(''); - $('#message').val(''); - $.notify(data.msg, 'success'); + data = data.responseJSON; + if (data.msg){ + $.notify(data.msg, 'error'); } else{ - $.notify(data.msg, 'error'); + $.notify(locale.ERROR_OCCURRED, 'error'); } + }, + success: function(data) { + $('#recipient').val(''); + $('#inviteModal').modal('hide'); + $('#email-list-invite').find('.email-entry:not(:last)').remove(); + $('#email-list-invite').find('input').val(''); + $('#message').val(''); + $.notify(data.msg, 'success'); } }); }); diff --git a/vroom.pl b/vroom.pl index 0d51463..f2a2718 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1251,9 +1251,10 @@ any '/api' => sub { return $self->render( json => { status => 'error', - msg => 'UNSUPPORTED_LANG' + msg => $self->l('UNSUPPORTED_LANG'), + err => 'UNSUPPORTED_LANG' }, - status => 503 + status => 400 ); } $self->session(language => $req->{param}->{language}); @@ -1271,8 +1272,8 @@ any '/api' => sub { param => $req->{param} ); - # Here are mthod not tied to a room - if ($req->{action} eq 'get_room_list'){ + # Here are method not tied to a room + if ($res && $req->{action} eq 'get_room_list'){ my $rooms = $self->get_room_list; # Blank out a few param we don't need foreach my $r (keys %{$rooms}){ @@ -1293,9 +1294,10 @@ any '/api' => sub { return $self->render( json => { 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 @@ -1306,8 +1308,10 @@ any '/api' => sub { return $self->render( json => { 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( json => { 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); @@ -1339,7 +1345,7 @@ any '/api' => sub { return $self->render( json => { status => 'success', - msg => sprintf($self->l('INVITE_SENT_TO_s'), join("\n", @$rcpts)) + msg => sprintf($self->l('INVITE_SENT_TO_s'), join("\n", @$rcpts)), } ); }