Fix API response to show correct error.

This commit is contained in:
Dane Everitt 2017-05-22 19:25:26 -05:00
parent 72c0330486
commit cce27dfff1
No known key found for this signature in database
GPG Key ID: EEA66103B3D71F53
2 changed files with 8 additions and 7 deletions

View File

@ -7,6 +7,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
### Fixed ### Fixed
* Fixes a bug preventing the use of services that have no variables attached to them. * Fixes a bug preventing the use of services that have no variables attached to them.
* Fixes 'Remember Me' checkbox being ignored when using 2FA on an account. * Fixes 'Remember Me' checkbox being ignored when using 2FA on an account.
* API now returns a useful error displaying what went wrong rather than an obscure 'An Error was Encountered' message when API issues arise.
### Changed ### Changed
* Renamed session cookies from `laravel_session` to `pterodactyl_session`. * Renamed session cookies from `laravel_session` to `pterodactyl_session`.

View File

@ -48,16 +48,16 @@ class Handler extends ExceptionHandler
if ($request->expectsJson() || $request->isJson() || $request->is(...config('pterodactyl.json_routes'))) { if ($request->expectsJson() || $request->isJson() || $request->is(...config('pterodactyl.json_routes'))) {
$exception = $this->prepareException($exception); $exception = $this->prepareException($exception);
if (config('app.debug')) { if (config('app.debug') || $this->isHttpException($exception)) {
$report = [ $displayError = $exception->getMessage();
'code' => (! $this->isHttpException($exception)) ?: $exception->getStatusCode(), } else {
'message' => class_basename($exception) . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine(), $displayError = 'An unhandled exception was encountered with this request.';
];
} }
$response = response()->json([ $response = response()->json([
'error' => (config('app.debug')) ? $exception->getMessage() : 'An unhandled exception was encountered with this request.', 'error' => $displayError,
'exception' => ! isset($report) ?: $report, 'http_code' => (! $this->isHttpException($exception)) ?: $exception->getStatusCode(),
'trace' => (! config('app.debug')) ? null : class_basename($exception) . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine(),
], ($this->isHttpException($exception)) ? $exception->getStatusCode() : 500, [], JSON_UNESCAPED_SLASHES); ], ($this->isHttpException($exception)) ? $exception->getStatusCode() : 500, [], JSON_UNESCAPED_SLASHES);
parent::report($exception); parent::report($exception);