Skip to content

Commit be48fbd

Browse files
committed
Fix allocation selection
1 parent ae843a7 commit be48fbd

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

app/Http/Controllers/Server/AjaxController.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,24 +211,24 @@ public function postSetConnection(Request $request, $uuid)
211211
}
212212

213213
try {
214-
215214
$repo = new Repositories\ServerRepository;
216215
$repo->changeBuild($server->id, [
217216
'default' => $request->input('connection'),
218217
]);
219218
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.');
220-
221-
} catch (\Exception $e) {
222-
if ($e instanceof \Pterodactyl\Exceptions\DisplayException || $e instanceof \Pterodactyl\Exceptions\DisplayValidationException) {
223-
return response()->json([
224-
'error' => $e->getMessage(),
225-
], 503);
226-
} else {
227-
Log::error($e);
228-
return response()->json([
229-
'error' => 'An unhandled exception occured while attemping to modify the default connection for this server.'
230-
], 503);
231-
}
219+
} catch (\Pterodactyl\Exceptions\DisplayValidationException $ex) {
220+
return response()->json([
221+
'error' => json_decode($ex->getMessage(), true),
222+
], 503);
223+
} catch (\Pterodactyl\Exceptions\DisplayException $ex) {
224+
return response()->json([
225+
'error' => $ex->getMessage(),
226+
], 503);
227+
} catch (\Exception $ex) {
228+
Log::error($ex);
229+
return response()->json([
230+
'error' => 'An unhandled exception occured while attemping to modify the default connection for this server.'
231+
], 503);
232232
}
233233
}
234234

app/Repositories/ServerRepository.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,9 @@ public function changeBuild($id, array $data)
416416
if (isset($data['default'])) {
417417
list($ip, $port) = explode(':', $data['default']);
418418
if ($ip !== $server->ip || $port !== $server->port) {
419-
$allocation = Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->get();
419+
$allocation = Models\Allocation::where('ip', $ip)->where('port', $port)->where('assigned_to', $server->id)->first();
420420
if (!$allocation) {
421-
throw new DisplayException('The assigned default connection (' . $ip . ':' . $port . ') is not allocated to this server.');
421+
throw new DisplayException('The requested default connection (' . $ip . ':' . $port . ') is not allocated to this server.');
422422
}
423423

424424
$server->ip = $ip;
@@ -532,6 +532,10 @@ public function changeBuild($id, array $data)
532532
} catch (\GuzzleHttp\Exception\TransferException $ex) {
533533
DB::rollBack();
534534
throw new DisplayException('An error occured while attempting to update the configuration: ' . $ex->getMessage());
535+
} catch (\Exception $ex) {
536+
DB::rollBack();
537+
Log::error($ex);
538+
throw $ex;
535539
}
536540

537541
}

0 commit comments

Comments
 (0)