/** * Creates the error Response associated with the given Exception. * * @param \Exception $exception An \Exception instance * * @return Response A Response instance */ public function createResponse(\Exception $exception) { // defaults $content = ''; $title = ''; // try and get decent values try { $code = 500; $title = 'We\'re sorry, but it looks like something went wrong.'; $exception = FlattenException::create($exception); if (PHP_SAPI === 'cli') { // we are on the command line, so get the error in a clean format $content = FlattenExceptionFormatter::formatExceptionPlain($exception); // dump it out and exit with an error code echo $content; exit(1); } else { $content = $this->decorate(FlattenExceptionFormatter::formatException($exception), $title); } } catch (\Exception $e) { $title = 'We\'re sorry, but it looks like something went wrong.'; $content = $this->decorate('', $title); } // build a response out of anything we got return new Response($content, $code); }