Change exception handling for display exception

This commit is contained in:
Dane Everitt 2018-03-10 13:02:41 -06:00
parent ef371a508d
commit e5c59c4984
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
3 changed files with 40 additions and 7 deletions

View file

@ -15,6 +15,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
* Sessions handled through redis now use a seperate database (default `1`) to store session database to avoid logging users out when flushing the cache. * Sessions handled through redis now use a seperate database (default `1`) to store session database to avoid logging users out when flushing the cache.
* File manager UI improved to be clearer with buttons and cleaner on mobile. * File manager UI improved to be clearer with buttons and cleaner on mobile.
* reCAPTCHA's secret key position swapped with website key in advanced panel settings to be consistent with Google's reCAPTCHA dashboard. * reCAPTCHA's secret key position swapped with website key in advanced panel settings to be consistent with Google's reCAPTCHA dashboard.
* Changed DisplayException to handle its own logging correctly and check if the previous exception is marked as one that should not be logged.
## v0.7.5 (Derelict Dermodactylus) ## v0.7.5 (Derelict Dermodactylus)
### Fixed ### Fixed

View file

@ -2,9 +2,11 @@
namespace Pterodactyl\Exceptions; namespace Pterodactyl\Exceptions;
use Log; use Exception;
use Throwable; use Throwable;
use Psr\Log\LoggerInterface;
use Illuminate\Http\Response; use Illuminate\Http\Response;
use Illuminate\Container\Container;
use Prologue\Alerts\AlertsMessageBag; use Prologue\Alerts\AlertsMessageBag;
class DisplayException extends PterodactylException class DisplayException extends PterodactylException
@ -31,10 +33,6 @@ class DisplayException extends PterodactylException
{ {
parent::__construct($message, $code, $previous); parent::__construct($message, $code, $previous);
if (! is_null($previous)) {
Log::{$level}($previous);
}
$this->level = $level; $this->level = $level;
} }
@ -70,8 +68,31 @@ class DisplayException extends PterodactylException
]), method_exists($this, 'getStatusCode') ? $this->getStatusCode() : Response::HTTP_BAD_REQUEST); ]), method_exists($this, 'getStatusCode') ? $this->getStatusCode() : Response::HTTP_BAD_REQUEST);
} }
app()->make(AlertsMessageBag::class)->danger($this->getMessage())->flash(); Container::getInstance()->make(AlertsMessageBag::class)->danger($this->getMessage())->flash();
return redirect()->back()->withInput(); return redirect()->back()->withInput();
} }
/**
* Log the exception to the logs using the defined error level only if the previous
* exception is set.
*
* @return mixed
*
* @throws \Exception
*/
public function report()
{
if (! $this->getPrevious() instanceof Exception || ! Handler::isReportable($this->getPrevious())) {
return null;
}
try {
$logger = Container::getInstance()->make(LoggerInterface::class);
} catch (Exception $ex) {
throw $this->getPrevious();
}
return $logger->{$this->getErrorLevel()}($this->getPrevious());
}
} }

View file

@ -5,6 +5,7 @@ namespace Pterodactyl\Exceptions;
use Exception; use Exception;
use PDOException; use PDOException;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Illuminate\Container\Container;
use Illuminate\Auth\AuthenticationException; use Illuminate\Auth\AuthenticationException;
use Illuminate\Session\TokenMismatchException; use Illuminate\Session\TokenMismatchException;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
@ -24,7 +25,6 @@ class Handler extends ExceptionHandler
protected $dontReport = [ protected $dontReport = [
AuthenticationException::class, AuthenticationException::class,
AuthorizationException::class, AuthorizationException::class,
DisplayException::class,
HttpException::class, HttpException::class,
ModelNotFoundException::class, ModelNotFoundException::class,
RecordNotFoundException::class, RecordNotFoundException::class,
@ -201,6 +201,17 @@ class Handler extends ExceptionHandler
return ['errors' => [array_merge($error, $override)]]; return ['errors' => [array_merge($error, $override)]];
} }
/**
* Return an array of exceptions that should not be reported.
*
* @param \Exception $exception
* @return bool
*/
public static function isReportable(Exception $exception): bool
{
return (new static(Container::getInstance()))->shouldReport($exception);
}
/** /**
* Convert an authentication exception into an unauthenticated response. * Convert an authentication exception into an unauthenticated response.
* *