diff --git a/CHANGELOG.md b/CHANGELOG.md index 196b6fc85..14086eb38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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`. diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.php index 71d66cdc6..a801cdceb 100644 --- a/app/Exceptions/Handler.php +++ b/app/Exceptions/Handler.php @@ -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);