Change exception handling for display exception
This commit is contained in:
parent
ef371a508d
commit
e5c59c4984
3 changed files with 40 additions and 7 deletions
|
@ -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.
|
||||
* 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.
|
||||
* 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)
|
||||
### Fixed
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
namespace Pterodactyl\Exceptions;
|
||||
|
||||
use Log;
|
||||
use Exception;
|
||||
use Throwable;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Container\Container;
|
||||
use Prologue\Alerts\AlertsMessageBag;
|
||||
|
||||
class DisplayException extends PterodactylException
|
||||
|
@ -31,10 +33,6 @@ class DisplayException extends PterodactylException
|
|||
{
|
||||
parent::__construct($message, $code, $previous);
|
||||
|
||||
if (! is_null($previous)) {
|
||||
Log::{$level}($previous);
|
||||
}
|
||||
|
||||
$this->level = $level;
|
||||
}
|
||||
|
||||
|
@ -70,8 +68,31 @@ class DisplayException extends PterodactylException
|
|||
]), 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ namespace Pterodactyl\Exceptions;
|
|||
use Exception;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Illuminate\Container\Container;
|
||||
use Illuminate\Auth\AuthenticationException;
|
||||
use Illuminate\Session\TokenMismatchException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
@ -24,7 +25,6 @@ class Handler extends ExceptionHandler
|
|||
protected $dontReport = [
|
||||
AuthenticationException::class,
|
||||
AuthorizationException::class,
|
||||
DisplayException::class,
|
||||
HttpException::class,
|
||||
ModelNotFoundException::class,
|
||||
RecordNotFoundException::class,
|
||||
|
@ -201,6 +201,17 @@ class Handler extends ExceptionHandler
|
|||
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.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue