Skip to content

Commit cce27df

Browse files
committed
Fix API response to show correct error.
1 parent 72c0330 commit cce27df

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This project follows [Semantic Versioning](http://semver.org) guidelines.
77
### Fixed
88
* Fixes a bug preventing the use of services that have no variables attached to them.
99
* Fixes 'Remember Me' checkbox being ignored when using 2FA on an account.
10+
* API now returns a useful error displaying what went wrong rather than an obscure 'An Error was Encountered' message when API issues arise.
1011

1112
### Changed
1213
* Renamed session cookies from `laravel_session` to `pterodactyl_session`.

app/Exceptions/Handler.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ public function render($request, Exception $exception)
4848
if ($request->expectsJson() || $request->isJson() || $request->is(...config('pterodactyl.json_routes'))) {
4949
$exception = $this->prepareException($exception);
5050

51-
if (config('app.debug')) {
52-
$report = [
53-
'code' => (! $this->isHttpException($exception)) ?: $exception->getStatusCode(),
54-
'message' => class_basename($exception) . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine(),
55-
];
51+
if (config('app.debug') || $this->isHttpException($exception)) {
52+
$displayError = $exception->getMessage();
53+
} else {
54+
$displayError = 'An unhandled exception was encountered with this request.';
5655
}
5756

5857
$response = response()->json([
59-
'error' => (config('app.debug')) ? $exception->getMessage() : 'An unhandled exception was encountered with this request.',
60-
'exception' => ! isset($report) ?: $report,
58+
'error' => $displayError,
59+
'http_code' => (! $this->isHttpException($exception)) ?: $exception->getStatusCode(),
60+
'trace' => (! config('app.debug')) ? null : class_basename($exception) . ' in ' . $exception->getFile() . ' on line ' . $exception->getLine(),
6161
], ($this->isHttpException($exception)) ? $exception->getStatusCode() : 500, [], JSON_UNESCAPED_SLASHES);
6262

6363
parent::report($exception);

0 commit comments

Comments
 (0)