Skip to content

Commit

Permalink
Better exception JSON responses
Browse files Browse the repository at this point in the history
Resolves #7406
  • Loading branch information
brandonkelly committed Jan 22, 2021
1 parent eeb2d25 commit 5775433
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG-v3.6.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
- `craft\services\Gql::getValidationRules()` now has an `$isIntrospectionQuery` argument.
- `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))
- Craft no longer reports PHP deprecation errors.
- Exception JSON responses now include `exception`, `file`, `line`, and `trace` keys. ([#7406](https://github.com/craftcms/cms/issues/7406))
- GraphQL queries now support eager-loading for arguments provided as input objects.
- Made it easier to extend Craft’s Codeception testing module with custom code. ([#7339](https://github.com/craftcms/cms/issues/7339))
- Updated Yii to 2.0.40.
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Added
- Added `craft\test\fixtures\elements\BaseContentFixture`.

### Changed
- Exception JSON responses now include `exception`, `file`, `line`, and `trace` keys. ([#7406](https://github.com/craftcms/cms/issues/7406))

### Fixed
- 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))

Expand Down
18 changes: 17 additions & 1 deletion src/web/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,23 @@ public function runAction($id, $params = [])
} else {
$statusCode = 500;
}
return $this->asErrorJson($message)

if (YII_DEBUG) {
$response = $this->asJson([
'error' => $message,
'exception' => get_class($e),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => array_map(function($step) {
unset($step['args']);
return $step;
}, $e->getTrace()),
]);
} else {
$response = $this->asErrorJson($message);
}

return $response
->setStatusCode($statusCode);
}
throw $e;
Expand Down

0 comments on commit 5775433

Please sign in to comment.