src/Application.php
public function minionError(\Exception $ex, $code) {
        $handler = new ExceptionHandler($this['debug']);
        $exception = FlattenException::create($ex);
        $response = Response::create($handler->getHtml($exception), $code, $exception->getHeaders())
            ->setCharset(\ini_get('default_charset'))
        ;

        if($this['debug'])
            return $response;
        else {
            $content = <<<HTML
<!DOCTYPE html>
<html>
    <head><title>Error $code</title></head>
    <body><h1>Error {$exception->getMessage()} occured</h1></body>
</html>
HTML;

            if($this['minion.useTwig'] && isset($this['twig'])) {
                $twig = $this['twig'];
                $tpl = "Static/$code.html.twig";
                if(!Utils::templateExists($twig, $tpl))
                    $content = \str_replace('%d', $code, $content);
                else
                    $content = $twig->render($tpl, ['exception' => $ex]);
            } elseif(\file_exists($tpl = Utils::fixPath($this->getRootDir() . "/Static/$code.html.php")))
                $content = Utils::renderPhpTemplate($tpl, ['exception' => $ex]);

            $response->setStatusCode($code);
            $response->setContent($content);

            return $response;
        }
    }
public function minionError(\Exception $ex, $code) {
        $handler = new ExceptionHandler($this['debug']);
        $exception = FlattenException::create($ex);
        $response = Response::create($handler->getHtml($exception), $code, $exception->getHeaders())
            ->setCharset(\ini_get('default_charset'))
        ;

        if($this['debug'])
            return $response;
        else {
            $content = <<<HTML
<!DOCTYPE html>
<html>
    <head><title>Error $code</title></head>
    <body><h1>Error {$exception->getMessage()} occured</h1></body>
</html>
HTML;

            if($this['minion.useTwig'] && isset($this['twig'])) {
                $twig = $this['twig'];
                $tpl = "Static/$code.html.twig";
                if(!Utils::templateExists($twig, $tpl))
                    $content = \str_replace('%d', $code, $content);
                else
                    $content = $twig->render($tpl, ['exception' => $ex]);
            } elseif(\file_exists($tpl = Utils::fixPath($this->getRootDir() . "/Static/$code.html.php")))
                $content = Utils::renderPhpTemplate($tpl, ['exception' => $ex]);

            $response->setStatusCode($code);
            $response->setContent($content);

            return $response;
        }
    }
@internal

Handle errors and exceptions thrown by entire application.

@param \Exception $ex   Any exception
@param integer    $code HTTP status code

@return Response Response to the client with nice error page