From be48fbd418939df15fc772ada3da5337664ea02d Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Fri, 22 Jan 2016 21:43:56 -0500 Subject: [PATCH] Fix allocation selection --- .../Controllers/Server/AjaxController.php | 26 +++++++++---------- app/Repositories/ServerRepository.php | 8 ++++-- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/Server/AjaxController.php b/app/Http/Controllers/Server/AjaxController.php index 9e788061a..4110958a1 100644 --- a/app/Http/Controllers/Server/AjaxController.php +++ b/app/Http/Controllers/Server/AjaxController.php @@ -211,24 +211,24 @@ class AjaxController extends Controller } try { - $repo = new Repositories\ServerRepository; $repo->changeBuild($server->id, [ 'default' => $request->input('connection'), ]); return response('The default connection for this server has been updated. Please be aware that you will need to restart your server for this change to go into effect.'); - - } catch (\Exception $e) { - if ($e instanceof \Pterodactyl\Exceptions\DisplayException || $e instanceof \Pterodactyl\Exceptions\DisplayValidationException) { - return response()->json([ - 'error' => $e->getMessage(), - ], 503); - } else { - Log::error($e); - return response()->json([ - 'error' => 'An unhandled exception occured while attemping to modify the default connection for this server.' - ], 503); - } + } catch (\Pterodactyl\Exceptions\DisplayValidationException $ex) { + return response()->json([ + 'error' => json_decode($ex->getMessage(), true), + ], 503); + } catch (\Pterodactyl\Exceptions\DisplayException $ex) { + return response()->json([ + 'error' => $ex->getMessage(), + ], 503); + } catch (\Exception $ex) { + Log::error($ex); + return response()->json([ + 'error' => 'An unhandled exception occured while attemping to modify the default connection for this server.' + ], 503); } } diff --git a/app/Repositories/ServerRepository.php b/app/Repositories/ServerRepository.php index 555dcb229..6d8fa7654 100644 --- a/app/Repositories/ServerRepository.php +++ b/app/Repositories/ServerRepository.php @@ -416,9 +416,9 @@ class ServerRepository if (isset($data['default'])) { list($ip, $port) = explode(':', $data['default']); if ($ip !== $server->ip || $port !== $server->port) { - $allocation = Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->get(); + $allocation = Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->first(); if (!$allocation) { - throw new DisplayException('The assigned default connection (' . $ip . ':' . $port . ') is not allocated to this server.'); + throw new DisplayException('The requested default connection (' . $ip . ':' . $port . ') is not allocated to this server.'); } $server->ip = $ip; @@ -532,6 +532,10 @@ class ServerRepository } catch (\GuzzleHttp\Exception\TransferException $ex) { DB::rollBack(); throw new DisplayException('An error occured while attempting to update the configuration: ' . $ex->getMessage()); + } catch (\Exception $ex) { + DB::rollBack(); + Log::error($ex); + throw $ex; } }