/**
  * {@inheritdoc}
  */
 public function handle($showDetails = true)
 {
     // Should we return JSON?
     if (($returnAsJson = $this->returnAsJson()) === true) {
         $this->response->type('application/json');
     }
     // Set the response body
     if ($showDetails) {
         $this->response->body($this->getDetailedError($returnAsJson));
     } else {
         $this->response->body($this->getGenericError($returnAsJson));
     }
     // Send the response along with appropriate headers
     if ($this->exception instanceof RequestException) {
         $status = $this->exception->getCode();
         if ($this->exception instanceof MethodNotAllowedException) {
             $this->response->header('allows', implode(',', $this->exception->getAllowedMethods()));
         }
     } else {
         $status = 500;
     }
     $this->response->status($status)->send();
     // Return false to stop further error handling
     return false;
 }
 /**
  * Dispatches the route and returns the response.
  *
  * @access  public
  * @return  \mako\http\Response
  */
 public function dispatch()
 {
     $returnValue = $this->beforeFilters();
     if (!empty($returnValue)) {
         $this->response->body($returnValue);
     } else {
         $action = $this->route->getAction();
         if ($action instanceof Closure) {
             $this->dispatchClosure($action);
         } else {
             $this->dispatchController($action);
         }
         if (!$this->skipAfterFilters) {
             $this->afterFilters();
         }
     }
     return $this->response;
 }
 /**
  * Builds and returns a basic HTTP authentication response.
  *
  * @access  protected
  * @return  \mako\http\Response
  */
 protected function basicHTTPAuthenticationResponse()
 {
     $response = new Response($this->request);
     $response->body('Authentication required.');
     $response->header('www-authenticate', 'basic');
     $response->status(401);
     return $response;
 }