1
1
mirror of https://github.com/pterodactyl/panel.git synced 2024-10-27 12:22:28 +01:00

Allow exceptions to throw their own error codes from within.

Temp work-around for tons of logic until upgrade to 5.5 is done.
This commit is contained in:
Dane Everitt 2017-09-24 12:32:29 -05:00
parent c43ab595cf
commit 0f0c319ec0
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 10 additions and 1 deletions

View File

@ -11,6 +11,7 @@ use Illuminate\Auth\Access\AuthorizationException;
use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Database\Eloquent\ModelNotFoundException;
use Pterodactyl\Exceptions\Model\DataValidationException; use Pterodactyl\Exceptions\Model\DataValidationException;
use Symfony\Component\HttpKernel\Exception\HttpException; use Symfony\Component\HttpKernel\Exception\HttpException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler class Handler extends ExceptionHandler
@ -28,6 +29,7 @@ class Handler extends ExceptionHandler
DisplayValidationException::class, DisplayValidationException::class,
HttpException::class, HttpException::class,
ModelNotFoundException::class, ModelNotFoundException::class,
RecordNotFoundException::class,
TokenMismatchException::class, TokenMismatchException::class,
ValidationException::class, ValidationException::class,
]; ];
@ -69,7 +71,7 @@ class Handler extends ExceptionHandler
$response = response()->json( $response = response()->json(
[ [
'error' => $displayError, 'error' => $displayError,
'http_code' => (! $this->isHttpException($exception)) ?: $exception->getStatusCode(), 'http_code' => (method_exists($exception, 'getStatusCode')) ? $exception->getStatusCode() : 500,
'trace' => (! config('app.debug')) ? null : $exception->getTrace(), 'trace' => (! config('app.debug')) ? null : $exception->getTrace(),
], ],
$this->isHttpException($exception) ? $exception->getStatusCode() : 500, $this->isHttpException($exception) ? $exception->getStatusCode() : 500,

View File

@ -26,4 +26,11 @@ namespace Pterodactyl\Exceptions\Repository;
class RecordNotFoundException extends \Exception class RecordNotFoundException extends \Exception
{ {
/**
* @return int
*/
public function getStatusCode()
{
return 404;
}
} }