HTTP codes for room creation

master
Daniel Berteaud 10 years ago
parent d4db36765a
commit 2ebe33060b
  1. 19
      public/js/vroom.js
  2. 6
      vroom.pl

@ -348,23 +348,24 @@ function initIndex(){
roomName: $('#roomName').val(), roomName: $('#roomName').val(),
}, },
success: function(data) { success: function(data) {
if (data.status == 'success'){ room = data.room;
room = data.room; window.location.assign(rootUrl + data.room);
window.location.assign(rootUrl + data.room); },
} error: function(data){
else if (data.err && data.err == 'ERROR_NAME_CONFLICT' ){ data = data.responseJSON;
if (data.err && data.err == 'ERROR_NAME_CONFLICT' ){
room = data.room; room = data.room;
$('#conflictModal').modal('show'); $('#conflictModal').modal('show');
} }
else{ else if (data.msg){
$('#roomName').parent().parent().notify(data.msg, { $('#roomName').parent().parent().notify(data.msg, {
class: 'error', class: 'error',
position: 'bottom center' position: 'bottom center'
}); });
} }
}, else{
error: function(){ $.notify(locale.ERROR_OCCURRED, 'error');
$.notify(locale.ERROR_OCCURRED, 'error'); }
} }
}); });
} }

@ -1139,17 +1139,17 @@ post '/create' => sub {
if (!$self->valid_room_name($name)){ if (!$self->valid_room_name($name)){
$json->{err} = 'ERROR_NAME_INVALID'; $json->{err} = 'ERROR_NAME_INVALID';
$json->{msg} = $self->l('ERROR_NAME_INVALID'); $json->{msg} = $self->l('ERROR_NAME_INVALID');
return $self->render(json => $json); return $self->render(json => $json, status => 400);
} }
elsif ($self->get_room_by_name($name)){ elsif ($self->get_room_by_name($name)){
$json->{err} = 'ERROR_NAME_CONFLICT'; $json->{err} = 'ERROR_NAME_CONFLICT';
$json->{msg} = $self->l('ERROR_NAME_CONFLICT'); $json->{msg} = $self->l('ERROR_NAME_CONFLICT');
return $self->render(json => $json); return $self->render(json => $json, status => 409);
} }
if (!$self->create_room($name,$self->session('name'))){ if (!$self->create_room($name,$self->session('name'))){
$json->{err} = 'ERROR_OCCURRED'; $json->{err} = 'ERROR_OCCURRED';
$json->{msg} = $self->l('ERROR_OCCURRED'); $json->{msg} = $self->l('ERROR_OCCURRED');
return $self->render(json => $json); return $self->render(json => $json, status => 500);
} }
$json->{status} = 'success'; $json->{status} = 'success';
$json->{err} = ''; $json->{err} = '';

Loading…
Cancel
Save