/** * Apply the queued headers to the response. * * If the builder has no Origin, or if there are no allowed domains, * or if the allowed domains do not match the Origin header no headers will be applied. * * @return \CoreTyson\Network\Response */ public function build() { if (empty($this->_origin)) { return $this->_response; } if (isset($this->_headers['Access-Control-Allow-Origin'])) { $this->_response->header($this->_headers); } return $this->_response; }
public function processError($request, $exception) { $response = new Response(); $viewVars = ["exception" => $exception]; $code = 500; $errorCode = $exception->getCode(); if ($errorCode >= 400 && $errorCode < 506) { $code = $errorCode; } $response->statusCode($code); $viewVars["code"] = $code; if (method_exists($exception, 'responseHeader')) { $response->header($exception->responseHeader()); } if ($request) { $viewVars["url"] = $request->url(); } $isDebug = Configuration::getInstance()->get("debug"); if ($isDebug) { $viewVars['trace'] = Debugger::formatTrace($exception->getTrace(), ['format' => 'array', 'args' => false]); } $message = $exception->getMessage(); $isHttpException = $exception instanceof HttpException; if (!$isDebug && !$isHttpException) { if ($code < 500) { $message = \CoreTyson\tr('cake', 'Not Found'); } else { $message = \CoreTyson\tr('cake', 'An Internal Error Has Occurred.'); } } $viewVars["message"] = $message; $template = "error" . $code; if (!$isDebug && !$isHttpException) { $template = 'error500'; if ($code < 500) { $template = 'error400'; } } if ($isHttpException) { $template = 'error500'; if ($code < 500) { $template = 'error400'; } } if ($exception instanceof PDOException) { $template = 'pdo_error'; } try { $view = new View(); $response->body($view->render("Error/" . $template)); } catch (MissingTemplateException $e) { return $this->_outputMessageSafe('error500'); } catch (MissingPluginException $e) { $attributes = $e->getAttributes(); if (isset($attributes['plugin']) && $attributes['plugin'] === $this->controller->plugin) { $this->controller->plugin = null; } return $this->_outputMessageSafe('error500'); } catch (Exception $e) { return $this->_outputMessageSafe('error500'); } }