/**
  * Convert an exception to a response
  *
  * @param \Exception $exception
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function handleException($exception)
 {
     if (!$exception instanceof FlattenException) {
         $exception = FlattenException::create($exception);
     }
     $handler = new BaseExceptionHandler($this->debug);
     $decorated = $this->decorate($handler->getContent($exception), $handler->getStylesheet($exception));
     return new Response($decorated, $exception->getStatusCode(), $exception->getHeaders());
 }
<?php

use Siphon\Exception\FlattenException;
use Siphon\Exception\HttpException;
describe("FlattenException", function () {
    it("flattens an instance of HttpExceptionInterface", function () {
        $e = FlattenException::create(new HttpException(404, "Not Found"));
        expect($e->getStatusCode())->toBe(404);
        expect($e->getMessage())->toBe('Not Found');
        expect($e->getHeaders())->toBe([]);
        expect($e->getClass())->toBe('Siphon\\Exception\\HttpException');
    });
    it("flattens an Exception", function () {
        $e = FlattenException::create(new Exception('Whoops', 0, new Exception('Whoops')));
        expect($e->getStatusCode())->toBe(500);
        expect($e->getMessage())->toBe('Whoops');
        expect($e->getClass())->toBe('Exception');
        expect($e->getPrevious())->toBeAnInstanceOf('Siphon\\Exception\\FlattenException');
    });
});