Skip to content

Commit 0f0c319

Browse files
committed
Allow exceptions to throw their own error codes from within.
Temp work-around for tons of logic until upgrade to 5.5 is done.
1 parent c43ab59 commit 0f0c319

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

app/Exceptions/Handler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Database\Eloquent\ModelNotFoundException;
1212
use Pterodactyl\Exceptions\Model\DataValidationException;
1313
use Symfony\Component\HttpKernel\Exception\HttpException;
14+
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
1415
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
1516

1617
class Handler extends ExceptionHandler
@@ -28,6 +29,7 @@ class Handler extends ExceptionHandler
2829
DisplayValidationException::class,
2930
HttpException::class,
3031
ModelNotFoundException::class,
32+
RecordNotFoundException::class,
3133
TokenMismatchException::class,
3234
ValidationException::class,
3335
];
@@ -69,7 +71,7 @@ public function render($request, Exception $exception)
6971
$response = response()->json(
7072
[
7173
'error' => $displayError,
72-
'http_code' => (! $this->isHttpException($exception)) ?: $exception->getStatusCode(),
74+
'http_code' => (method_exists($exception, 'getStatusCode')) ? $exception->getStatusCode() : 500,
7375
'trace' => (! config('app.debug')) ? null : $exception->getTrace(),
7476
],
7577
$this->isHttpException($exception) ? $exception->getStatusCode() : 500,

app/Exceptions/Repository/RecordNotFoundException.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@
2626

2727
class RecordNotFoundException extends \Exception
2828
{
29+
/**
30+
* @return int
31+
*/
32+
public function getStatusCode()
33+
{
34+
return 404;
35+
}
2936
}

0 commit comments

Comments
 (0)