Skip to content

Commit 5775433

Browse files
committed
Better exception JSON responses
Resolves #7406
1 parent eeb2d25 commit 5775433

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG-v3.6.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
- `craft\services\Gql::getValidationRules()` now has an `$isIntrospectionQuery` argument.
160160
- `Craft.formatNumber()` and other D3-based number formatting now uses a dynamically-generated locale definition based on info pulled from the application’s formatting locale. ([#7341](https://github.com/craftcms/cms/issues/7341))
161161
- Craft no longer reports PHP deprecation errors.
162+
- Exception JSON responses now include `exception`, `file`, `line`, and `trace` keys. ([#7406](https://github.com/craftcms/cms/issues/7406))
162163
- GraphQL queries now support eager-loading for arguments provided as input objects.
163164
- Made it easier to extend Craft’s Codeception testing module with custom code. ([#7339](https://github.com/craftcms/cms/issues/7339))
164165
- Updated Yii to 2.0.40.

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
### Added
66
- Added `craft\test\fixtures\elements\BaseContentFixture`.
77

8+
### Changed
9+
- Exception JSON responses now include `exception`, `file`, `line`, and `trace` keys. ([#7406](https://github.com/craftcms/cms/issues/7406))
10+
811
### Fixed
912
- Fixed a bug where D3-formatted numbers were getting extra `.00`s added to them if the Intl extension wasn’t installed. ([#7402](https://github.com/craftcms/cms/issues/7402))
1013

src/web/Controller.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,23 @@ public function runAction($id, $params = [])
209209
} else {
210210
$statusCode = 500;
211211
}
212-
return $this->asErrorJson($message)
212+
213+
if (YII_DEBUG) {
214+
$response = $this->asJson([
215+
'error' => $message,
216+
'exception' => get_class($e),
217+
'file' => $e->getFile(),
218+
'line' => $e->getLine(),
219+
'trace' => array_map(function($step) {
220+
unset($step['args']);
221+
return $step;
222+
}, $e->getTrace()),
223+
]);
224+
} else {
225+
$response = $this->asErrorJson($message);
226+
}
227+
228+
return $response
213229
->setStatusCode($statusCode);
214230
}
215231
throw $e;

0 commit comments

Comments
 (0)