Subtle 3 black bugs

I have a small slim 3 application, and when I throw a slim exception it just shows a general error message:

Thin application error

A web site error has occurred. Sorry for temporary inconvenience.

In slim 2, you can do something like this to enable debugging mode giving you return paths, etc .:

$app->config('debug', true); 

Slim 3 doesn't seem to be the only one. Also, it seems to override my exception and error handlers.

How can I get slim to spit out errors, or at least call error handlers (which channel outputs to the kint for debugging information)

+6
source share
4 answers

Looking through the source code, you can initialize slim 3 with error display as follows:

 $app = new \Slim\App(['settings' => ['displayErrorDetails' => true]]); 

I am not sure if it is possible to change this parameter after the fact without replacing errorHandler at all.

+17
source

To show the full stack trace in the default exception handler, use what jv said.

If you want to handle exceptions in Slim yourself, you need to override Slim's default exception handler, because it will be used before your "not in Slim" error handler:

 $app = new \Slim\App(); $container = $app->getContainer(); $container['errorHandler'] = function(ServerRequestInterface $request, ResponseInterface $response, Exception $exception) { //Handle exception here } 
+2
source

Error handling is pretty well documented: http://www.slimframework.com/docs/handlers/error.html

 $app = new \Slim\App(); $c = $app->getContainer(); $c['errorHandler'] = function ($c) { return function ($request, $response, $exception) use ($c) { return $c['response']->withStatus(500) ->withHeader('Content-Type', 'text/html') ->write('Something went wrong!'); }; }; 
+2
source

Error handling is the best solution for this. You can do something like see error tracing

 $app = new \Slim\App(); $container = $app->getContainer(); $container['phpErrorHandler'] = $container['errorHandler'] = function ($c) { return function ($request, $response, $exception) use ($c) { return $c['response']->withStatus(500) ->withHeader('Content-Type', 'text/html') ->write('Something went wrong!<br><br>' . nl2br($error->getTraceAsString())); }; }; 
0
source

All Articles