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 Pterodactyl\Exceptions\Model\DataValidationException;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
@ -28,6 +29,7 @@ class Handler extends ExceptionHandler
DisplayValidationException::class,
HttpException::class,
ModelNotFoundException::class,
RecordNotFoundException::class,
TokenMismatchException::class,
ValidationException::class,
];
@ -69,7 +71,7 @@ class Handler extends ExceptionHandler
$response = response()->json(
[
'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(),
],
$this->isHttpException($exception) ? $exception->getStatusCode() : 500,

View file

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