protected function render($template, $data = array(), $status = array()) { try { $this->app->render($template, $data, $status); } catch (Twig_Error_Runtime $twigException) { $errorData = array(); $errorData['errorMessage'] = sprintf("An error was thrown while rendering view template from class %s. (%s)", get_class($this), $twigException->getMessage()); if ($this->app->getMode() == self::DEV_MODE) { $errorData['stackTrace'] = $twigException->getTraceAsString(); } $this->app->render(self::ERROR_TEMPLATE, $errorData, self::ERROR_CODE); } }
/** * Configures Honeybadger for the supplied Slim app for exception catching. * * @param Slim $app The Slim app. * @param array $options The config options. * @return Config The Honeybadger configuration. */ protected static function init(\Slim\Slim $app, array $options = array()) { if ($logger = $app->getLog()) { // Wrap the application logger. Honeybadger::$logger = new \Honeybadger\Logger\Slim($app->getLog()); } // Add missing, detected options. $options = Arr::merge(array('environment_name' => $app->getMode(), 'framework' => sprintf('Slim: %s', \Slim\Slim::VERSION)), $options); // Create a new configuration with the merged options. Honeybadger::$config = new Config(Honeybadger::$config->merge($options)); }
/** * If an exception is thrown, the Slim Framework will use this function to * render details (if in development mode) or present a basic error page. * * @param \Exception $e The Exception which caused the error */ public function outputException(\Exception $e) { $status = 500; // the user requested an unsupported content type if ($e instanceof Exception\ContentTypeException) { // this is a client error -> use the correct header in 4XX range $status = 406; $title = 'Not Acceptable'; $summary = 'Could not render list output in requested format'; // TODO: // add the available formats in response header // see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.7 // Unless it was a HEAD request, the response SHOULD include an entity // containing a list of available entity characteristics and location(s) // from which the user or user agent can choose the one most appropriate. // The entity format is specified by the media type given in the Content-Type // header field. Depending upon the format and the capabilities of the user agent, // selection of the most appropriate choice MAY be performed automatically. // However, this specification does not define any standard for such automatic selection. } elseif ($e instanceof Exception\AuthException) { $status = 401; $title = 'Unauthorized'; $summary = ''; // TODO } elseif ($e instanceof Exception\InvalidRequestException) { $status = 400; $title = 'Bad Request'; $summary = ''; // TODO } elseif ($e instanceof Exception\ConfigException) { $status = 500; $title = 'Server Error'; $summary = ''; // TODO } if ($this->app->getMode() === 'development') { // show details if we are in dev mode $op = PHP_EOL; $op .= " <h4>Request details –</h4>" . PHP_EOL; $op .= " <dl class=\"dl-horizontal\">" . PHP_EOL; foreach ($_SERVER as $key => $value) { $key = strtolower($key); $key = str_replace(array('-', '_'), ' ', $key); $key = preg_replace('#^http #', '', $key); $key = ucwords($key); if (is_array($value)) { $op .= "<dt>{$key}</dt><dd><pre>" . print_r($value, true) . "</pre></dd>" . PHP_EOL; } else { $op .= " <dt>{$key}</dt>" . PHP_EOL . " <dd>{$value}</dd>" . PHP_EOL; } } $op .= " </dl>" . PHP_EOL; $msg = $e->getMessage(); $summary = ''; if (($p = strpos($msg, ' // ')) !== false) { $summary = substr($msg, $p + 4) . '</p><p>'; $msg = substr($msg, 0, $p); } $this->outputError($status, 'Server Error', $summary . '<strong>' . $e->getFile() . '</strong> +' . $e->getLine(), $msg, "<h4>Stack trace –</h4>" . PHP_EOL . ' <pre class="white">' . $e->getTraceAsString() . '</pre>' . $op); } else { if (!isset($title)) { $title = 'Unexpected Error'; } if (!isset($summary)) { $summary = '</p><p>Apologies for any inconvenience, the problem has been logged and we\'ll get on to it ASAP.'; } if (!isset($extendedTitle)) { // $extendedTitle = 'Whoops! An unexpected error has occured...'; $extendedTitle = ''; } // show basic message $this->outputError($status, $title, $summary, $extendedTitle); } }
public function collect() { return $this->slim->getMode(); }