Skip to content

Commit cf31d42

Browse files
committed
Fix a bug causing DataIntegrityExceptions to not be caught correctly and cause a second exception... whoops.
1 parent 114afb8 commit cf31d42

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
1111
* Fixes the redis password not saving correctly when setting up the environment from the command line.
1212
* Fixes a bug with transaction handling in many areas of the application that would cause validation error messages
1313
and other session data to not be persisted properly when using the database as the session driver.
14+
* Fix a bug introduced at some point in the past that causes internal data integrity exceptions to not bubble up to
15+
the user correctly, leading to extraneous and confusing exception messages.
1416

1517
### Changed
1618
* `allocation_limit` for servers now defaults to a null value, and is not required in PATCH/POST requests when adding

app/Exceptions/Handler.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\HttpKernel\Exception\HttpException;
1616
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
1717
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
18+
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
1819

1920
class Handler extends ExceptionHandler
2021
{
@@ -153,6 +154,26 @@ public function render($request, Exception $exception)
153154
$connections->rollBack(0);
154155
}
155156

157+
// Because of some breaking change snuck into a Laravel update that didn't get caught
158+
// by any of the tests, exceptions implementing the HttpExceptionInterface get marked
159+
// as being HttpExceptions, but aren't actually implementing the HttpException abstract.
160+
//
161+
// This is incredibly annoying because we can't just temporarily override the handler to
162+
// allow these (at least without taking on a high maintenance cost). Laravel 5.8 fixes this,
163+
// so when we update (or have updated) this code can be removed.
164+
//
165+
// @see https://github.com/laravel/framework/pull/25975
166+
// @todo remove this code when upgrading to Laravel 5.8
167+
if ($exception instanceof HttpExceptionInterface && ! $exception instanceof HttpException) {
168+
$exception = new HttpException(
169+
$exception->getStatusCode(),
170+
$exception->getMessage(),
171+
$exception,
172+
$exception->getHeaders(),
173+
$exception->getCode()
174+
);
175+
}
176+
156177
return parent::render($request, $exception);
157178
}
158179

0 commit comments

Comments
 (0)