The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Continue after Error Handler Notice

Justin Kelley's Avatar

Justin Kelley

17 Mar, 2016 05:51 PM

I'm working on handling native php errors using Slim 3's error handling in conjunction with Monolog. I set up an error handler that converts Errors into Error Exceptions and then throws them over to Slim. I want to log everything, including notices and deprecation. The problem is that execution halts after the error is thrown.

I know $container['errorHandler'] needs to return a valid response object, but I want it to continue execution in the event of a NOTICE. Any suggestions on how to handle this? Here is a sample of the code:

return function ($request, $response, $e) use ($c) {
        switch ($e->getCode()) {
            case 8:
            case 1024:
            case 2048:
            case 8192:
            case 16384:
                $c->get('logger')->notice($e);
                return $response->withStatus(200);
                break;
            case 32:
            case 512:
                $c->get('logger')->warning($e);
                return $c['response']->withStatus(500)->withHeader('Content-Type', 'text/html')->write('Something went wrong!');
                break;
            default:
                $c->get('logger')->error($e);
                return $c['response']->withStatus(400)->withHeader('Content-Type', 'text/html')->write('Something went wrong!');
                break;
        }
    };

Thank you!

  1. Josh Lockhart closed this discussion on 12 Feb, 2021 07:37 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac