-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Custom exception handler #5355
Custom exception handler #5355
Conversation
Thank you. Please fix coding style, |
https://github.com/codeigniter4/CodeIgniter4/runs/4250147232?check_suite_focus=true |
I modified the test by creating new class instances. |
What do you mean? If something wrong, please create an issue or a PR. |
@iRedds You mean changing another test makes But in reality, there seems to be tests depending on other test results (global state). |
@kenjis Yes, that's what I meant. In CodeIgniterTest, all tests use a closure, and the closure is excluded when generating the list of routes. |
I'm not convinced this is the best solution. This was something I had been thinking about implementing and hadn't gotten to it quite yet. The first thing is that we already have a custom exception handler, and this solution is bypassing that and catching the exception before it makes it to the handler. The second is that it doesn't seem to allow custom handling of generic errors. Here's where I was heading with my thinking of how to do it: The exception handler that we already register simply:
Whether the handlers are defined in a config file, or in an overridden function, I'm not sure. Maybe a combination of the two? |
@lonnieezell Only exceptions that implement the CustomExceptionHandlerInterface interface are caught.
//controller method
public function someMethod()
{
try {
//throws MyException
} catch (MyException $e) {
return //response
}
}
public function someMethod2()
{
try {
//throws MyException
} catch (MyException $e) {
return //response
}
} by moving the try..catch block up one level.
At the expense of configuration files. I believe the config files should be config files. That is, they should not contain logic. Although initially I planned to make just a general exception handler, in which it would be possible to catch not only custom exceptions, but also exceptions of third-party libraries. It seems like it was in Laravel. namespace App\Exceptions;
class Handler extends \Codeigniter\Exceptions\ExceptionHandler
{
public function render(RequestInterface $request, \Exception $exception)
{
if (exception1) {
// do something
}
if (exception2) {
// do something
}
}
} |
Description
I offer functionality for global handling of custom exceptions.
An exception for handling will be defined through the interface
An exception can be thrown from anywhere in the application.
Checklist: