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
* 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.
* API now returns a useful error displaying what went wrong rather than an obscure 'An Error was Encountered' message when API issues arise.
### Changed
* 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'))) {
$exception = $this->prepareException($exception);
if (config('app.debug')) {
$report = [
'code' => (! $this->isHttpException($exception)) ?: $exception->getStatusCode(),
'message' => class_basename($exception) . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine(),
];
if (config('app.debug') || $this->isHttpException($exception)) {
$displayError = $exception->getMessage();
} else {
$displayError = 'An unhandled exception was encountered with this request.';
}
$response = response()->json([
'error' => (config('app.debug')) ? $exception->getMessage() : 'An unhandled exception was encountered with this request.',
'exception' => ! isset($report) ?: $report,
'error' => $displayError,
'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);
parent::report($exception);