From 5645ff14c7a16e4ed50c5b142301dfdf4b9312d0 Mon Sep 17 00:00:00 2001 From: Daniel Berteaud Date: Thu, 5 Feb 2015 18:48:24 +0100 Subject: [PATCH] HTTP codes in promote_peer API call --- public/js/vroom.js | 17 +++++++++-------- vroom.pl | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/public/js/vroom.js b/public/js/vroom.js index ed5056b..020782e 100644 --- a/public/js/vroom.js +++ b/public/js/vroom.js @@ -1069,16 +1069,17 @@ function initVroom(room) { }) }, error: function(data) { - $.notify(locale.ERROR_OCCURRED, 'error'); - }, - success: function(data) { - if (data.status == 'success' && data.msg){ - webrtc.sendToAll('owner_promoted', {peer: id}); - $.notify(data.msg, 'success'); - } - else if (data.msg){ + data = data.responseJSON; + if (data.msg){ $.notify(data.msg, 'error'); } + else{ + $.notify(locale.ERROR_OCCURRED, 'error'); + } + }, + success: function(data) { + webrtc.sendToAll('owner_promoted', {peer: id}); + $.notify(data.msg, 'success'); } }); suspendButton($('#actionPromote_' + id)); diff --git a/vroom.pl b/vroom.pl index c19b9a6..b6db17f 100755 --- a/vroom.pl +++ b/vroom.pl @@ -1742,7 +1742,17 @@ any '/api' => sub { # Promote a participant to be owner of a room elsif ($req->{action} eq 'promote_peer'){ my $peer_id = $req->{param}->{peer_id}; - if ($peer_id && $self->promote_peer({room => $room->{name}, peer_id => $peer_id})){ + if (!$peer){ + return $self->render( + json => { + status => 'error', + msg => $self->l('ERROR_PEER_ID_MISSING'), + err => 'ERROR_PEER_ID_MISSING' + }, + status => 400 + ); + } + elsif ($self->promote_peer({room => $room->{name}, peer_id => $peer_id})){ return $self->render( json => { status => 'success', @@ -1754,7 +1764,9 @@ any '/api' => sub { json => { status => 'error', msg => $self->l('ERROR_OCCURRED') - } + err => 'ERROR_OCCURRED' + }, + status => 503 ); } # Wipe room data (chat history and etherpad content)