The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Disable Pretty Exceptions

david's Avatar


29 Jun, 2012 08:20 AM


I am using Slim for a REST API returning json responses.

How can I disable the PrettyExceptions middleware so that the error handler doesn't wrap my exceptions in the pretty HTML (!) output.

Thanks and cheers,


  1. Support Staff 1 Posted by Brian Nesbitt on 29 Jun, 2012 12:52 PM

    Brian Nesbitt's Avatar

    All "errors" are caught and re-thrown as exceptions. When the application is in debug = true mode then the exception is thrown which gets caught by the PrettyException middleware and renders a pretty exception. When the application is in debug = false then the registered error handler is called, and if no registered error handler exists then the default Slim::defaultError() handler is called.

    You can define your own error handler by passing in a callable to $app->error() as shown

    $app->error(function ( Exception $e ) use ($app) {
        echo "error : " . $e;

    Then, as mentioned above you have to set the application debug mode to false. You can either set that on app creation or afterwards using the config() function.

    $app = new Slim(array('debug' => false));


    $app->config('debug', false);
  2. 2 Posted by david on 30 Jun, 2012 10:54 AM

    david's Avatar

    Aha! Set debug mode to false. Awesome. ;-)

    Many thanks!

  3. david closed this discussion on 30 Jun, 2012 10:55 AM.

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

Keyboard shortcuts


? 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