Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't add custom HttpException class as a Logger exception #17334

Closed
uaoleg opened this issue May 31, 2019 · 2 comments
Closed

Can't add custom HttpException class as a Logger exception #17334

uaoleg opened this issue May 31, 2019 · 2 comments
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug

Comments

@uaoleg
Copy link
Contributor

uaoleg commented May 31, 2019

What steps will reproduce the problem?

  • Extend base HttpException, e.g. AllowedOnlyForAdminsHttpException
  • Add AllowedOnlyForAdminsHttpException to the list of except for Logger

What is the expected result?

All AllowedOnlyForAdminsHttpException exceptions are skipped

What do you get instead?

AllowedOnlyForAdminsHttpException exceptions are still logged

Additional info

Q A
Yii version 2.0.15

This logic is implemented in yii\base\ErrorHandler::logException() method:
https://github.com/yiisoft/yii2/blob/master/framework/base/ErrorHandler.php#L288

@samdark samdark added status:to be verified Needs to be reproduced and validated. type:bug Bug labels May 31, 2019
@alexkart
Copy link
Contributor

alexkart commented Jun 14, 2019

@uaoleg, this behavior is actually mentioned in the documentation https://www.yiiframework.com/doc/guide/2.0/en/runtime-logging

Info: When an HTTP exception is caught by the error handler, an error message will be logged with the category name in the format of yii\web\HttpException:ErrorCode. For example, the yii\web\NotFoundHttpException will cause an error message of category yii\web\HttpException:404.

For some reason, it was decided to set a category of the log message for http exceptions in this format.

@alexkart
Copy link
Contributor

alexkart commented Jun 14, 2019

You can extend your own exception class from UserException not HttpException and it will be ignored.

@mtangoo mtangoo closed this as completed Apr 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:to be verified Needs to be reproduced and validated. type:bug Bug
Projects
None yet
Development

No branches or pull requests

4 participants