From 34cf70989386b99b2b5c5005585df29009373f2e Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Wed, 4 Feb 2015 23:17:28 +0100 Subject: [PATCH] More HTTP codes fixes --- public/js/vroom.js | 19 ++++++++++--------- vroom.pl | 22 ++++++++++++++++------ 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/public/js/vroom.js b/public/js/vroom.js index ab787e0..4c7b3af 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -1836,18 +1836,19 @@ function initVroom(room) { }) }, error: function(data) { - $.notify(locale.ERROR_OCCURRED, 'error'); - }, - success: function(data) { - $('#authPass').val(''); - if (data.status == 'success'){ - $('#ownerAuthModal').modal('hide'); - getRoomInfo(); - $.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) { + $('#authPass').val(''); + $('#ownerAuthModal').modal('hide'); + getRoomInfo(); + $.notify(data.msg, 'success'); } }); }); diff --git a/vroom.pl b/vroom.pl index 4902476..320479a 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1547,8 +1547,10 @@ any '/api' => sub { return $self->render( json => { msg => $self->l('ERROR_OCCURRED'), + err => 'ERROR_OCCURRED', status => 'error' - } + }, + status => 503 ); } # Add or remove an email address to the list of email notifications @@ -1559,8 +1561,10 @@ any '/api' => sub { return $self->render( json => { msg => $self->l('ERROR_MAIL_INVALID'), + err => 'ERROR_MAIL_INVALID', status => 'error' - } + }, + status => 400 ); } elsif ($set eq 'on' && $self->add_notification($room->{name},$email)){ @@ -1582,8 +1586,10 @@ any '/api' => sub { return $self->render( json => { msg => $self->l('ERROR_OCCURRED'), + err => 'ERROR_OCCURRED', status => 'error' - } + }, + status => 503 ); } elsif ($req->{action} eq 'authenticate'){ @@ -1608,16 +1614,20 @@ any '/api' => sub { return $self->render( json => { status => 'error', - msg => $self->l('WRONG_PASSWORD') - } + msg => $self->l('WRONG_PASSWORD'), + err => 'WRONG_PASSWORD' + }, + status => 401 ); } # There's no owner password, so you cannot auth return $self->render( json => { msg => $self->l('NOT_ALLOWED'), + err => 'NOT_ALLOWED', status => 'error' - } + }, + status => 403 ); } # Return just room config