craft/web/ErrorHandler::renderException re-add left attributes from Yii2 or add an event to add those #11799
-
I usually control my REST Application states via Exceptions. In Craft 3 Yii2 did everything for me. For example in my Controller $i = $this->request->getBodyParam('someParam');
if($i === 0){
throw new HttpException(400, 'i must not be 0', 1);
}
if($i > 10){
throw new HttpException(400, 'i must not be larger than 10', 2);
} the responses would then be like {
name: 'Bad Request',
message: 'i must not be 0' | 'i must not be larger than 10',
status: 400,
code: 0 | 1
} I was able to check // display the error message
if (res.code === 0) {
// do something special, like prepare a new request with the better value instantly
}
// and so on However: Craft 4 does only this in a live environment {
name: 'Bad Request',
message: 'Bad Request'
} This one doesn't contain any useful information at all and a totally different response in dev mode. It would be awesome if there was an event for us so I can easily overwrite your response with the one from Yii2 again without the requirement to overwrite the entire class again. In a perfect world you would just call Yii2 Even more problematic now: depending of the response header, totally different data is passed... In Yii2 the structural exception response was always the same. Craft 4 shows a detailed response in case of an XML request and basically nothing in case of JSON. (To avoid confusions: I frequently use https://www.yiiframework.com/doc/api/2.0/yii-filters-contentnegotiator and it's a requirement for me provide different response types for different API users) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
This actually changed back in Craft 3.6 (5775433). I’ve just updated the code for the next Craft 3 and 4 releases, so all JSON error responses start including |
Beta Was this translation helpful? Give feedback.
This actually changed back in Craft 3.6 (5775433).
I’ve just updated the code for the next Craft 3 and 4 releases, so all JSON error responses start including
name
andcode
keys, andstatus
forHttpException
s regardless of Dev Mode, just like Yii does out of the box. (48b7ead)