Display a page for a HTTP status code.

@param string code    status code to set the http header.
@param string message an optional message to display together with the error code.

@return void
198154
public function statusCodeAction($code = null, $message = null)
    {
        $codes = [
            403 => "403 Forbidden",
            404 => "404 Not Found",
            500 => "500 Internal Server Error",
        ];

        // Key being integer also (unintentionally) prevents this action from direct url usage
        if (!$code || !in_array($code, $codes)) {
            throw new \Anax\Exception\NotFoundException("Not a valid HTTP status code.");
        }

           $title = $codes[$code];
           $this->di->response->setHeader($code);
           $this->di->theme->setTitle($title);
           $this->di->views->add('default/error', [
            'title' => $title,
            'content' => $message,
            'details' => $this->di->flash->getMessage(),
           ]);
    }
319501
protected function sendError(
        int $code,
        string $message,
        $data = null
    ) {
        $response = $this->prepareResponse();

        switch ($code) {
            case static::ERROR_INTERNAL_SERVER:
                $status = HttpResponse::HTTP_INTERNAL_SERVER_ERROR;
                break;

            case static::ERROR_INVALID_CREDENTIALS:
            case static::ERROR_UNAUTHENTICATED:
                $status = HttpResponse::HTTP_UNAUTHORIZED;
                $realm = $this->authentication['realm'] ?? null;
                $auth = 'Basic'
                    . ($realm !== null ? ' realm="' . $realm . '"' : '')
                    . ' charset="UTF-8"';
                $response->headers['WWW-Authenticate'] = $auth;
                break;

            case static::ERROR_INVALID_TOKEN:
                $status = HttpResponse::HTTP_UNAUTHORIZED;
                $realm = $this->authentication['realm'] ?? null;
                $auth = 'Bearer'
                    . ($realm !== null ? ' realm="' . $realm . '"' : '');
                $response->headers['WWW-Authenticate'] = $auth;
                break;

            case static::ERROR_METHOD_NOT_IMPLEMENTED:
                $status = HttpResponse::HTTP_NOT_IMPLEMENTED;
                $response->headers['Allow'] = $data;
                break;

            case static::ERROR_UNAUTHORIZED:
                $status = HttpResponse::HTTP_FORBIDDEN;
                break;

            case static::ERROR_INVALID_RESOURCE:
            case static::ERROR_INVALID_RESOURCE_ID:
            case static::ERROR_INVALID_RESOURCE_OFFSET:
            case static::ERROR_INVALID_RESOURCE_FOREIGN:
            case static::ERROR_INVALID_PAYLOAD:
            case static::ERROR_INVALID_QUERY_PARAMETER:
            case static::ERROR_UNKNOWN_FIELDS:
            case static::ERROR_READONLY_RESOURCE:
            case static::ERROR_FOREIGN_CONSTRAINT:
                $status = HttpResponse::HTTP_BAD_REQUEST;
                break;

            case static::ERROR_RESOURCE_NOT_FOUND:
                $status = HttpResponse::HTTP_NOT_FOUND;
                break;

            case static::ERROR_UNSUPPORTED_MEDIA_TYPE:
                $status = HttpResponse::HTTP_UNSUPPORTED_MEDIA_TYPE;
                break;

            case static::ERROR_METHOD_NOT_ALLOWED:
                $status = HttpResponse::HTTP_METHOD_NOT_ALLOWED;
                if ($data !== null) {
                    $response->headers['Allow'] = $data;
                }
                break;

            case static::ERROR_NOT_ACCEPTABLE:
                $status = HttpResponse::HTTP_NOT_ACCEPTABLE;
                break;

            case static::ERROR_UNKNOWN_ERROR:
            default:
                $actual_code = static::ERROR_UNKNOWN_ERROR;
                $status = HttpResponse::HTTP_INTERNAL_SERVER_ERROR;
                $message = 'Unknown error'
                    . (strlen($message) > 0 ? ': ' . $message : '');
                break;
        }
        $response->status = $status;

        $response->headers['Content-Type'] = 'application/json';
        $response->body = [
            'code' => $code,
            'message' => $message,
        ];

        throw new RouterException($response, $actual_code ?? $code);
    }
1278506
public function status($code) {
        if (isset($this->_httpCode[$code])) {
            header((isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1') . ' ' . $code . ' ' . $this->_httpCode[$code], true, $code);
        }
    }
857234
protected function response($message, $code)
  {
    Rest::response()->json([
      'status' => $message,
      'code' => $code
    ], $code);

    cancel();
  }
1189578
public function error($message) {
        $message = printPretty($message, $return=true);

        $hStream = CLI ? \STDERR : fopen('php://stderr', 'a');
        fwrite($hStream, $message);
        if (!CLI) fclose($hStream);
    }
827081
public function abort($code = 500, $message = '', array $headers = [])
    {
        $this->response->status($code);

        foreach ($headers as $key => $value) {
            $this->response->addHeader($key, $value);
        }

        if ($message == null) {
            $message = 'The trial was suspended.';
        }

        throw new HttpException($message);
    }
953060
protected static void error(
            final HttpServletResponse httpServletResponse, final String message, final HttpStatus code) {
        try {
            httpServletResponse.setContentType("text/plain");
            httpServletResponse.setStatus(code.value());
            setNoCache(httpServletResponse);
            try (PrintWriter out = httpServletResponse.getWriter()) {
                out.println("Error while processing request:");
                out.println(message);
            }

            LOGGER.error("Error while processing request: {}", message);
        } catch (IOException ex) {
            throw ExceptionUtils.getRuntimeException(ex);
        }
    }
189894
public function raise_error($code, $message)
    {
        if ($code == 403) {
            header('HTTP/1.1 403 Forbidden');
            die("Invalid Request");
        }

        $this->show_message("Application Error ($code): $message", 'error');
        $this->remote_response();
        exit;
    }
346392
public static function code_404($message = null, $exit = true) {
		if ($message !== null) {
			$message = ' (' . $message . ')';
		}

		header('HTTP/1.1 404 Not Found' . $message, true);
		echo '404 Not Found' . $message;

		if ($exit) {
			exit();
		}
	}
994767
public function sendResult($code, $mime, $message)
    {
        $this->sendHeader('HTTP/1.0 ' . $code);
        $this->sendHeader('Content-Type: ' . $mime);
        $this->sendResponse($message);
    }
508988
public function responseDenied ($message = "", $httpStatusCode = Response::HTTP_NOT_FOUND)
    {
        $response['state'] = $this::STATE_ERROR;
        $response['msg'] = $this->translator->trans($message);

        $view = View::create()
            ->setStatusCode($httpStatusCode)
            ->setData($response);

        return $this->viewhandler->handle($view);
    }
552372
protected function assertPageLoaded($uri, $message = null)
    {
        $status = $this->statusCode();

        try {
            $this->assertEquals(200, $status);
        } catch (PHPUnitException $e) {
            $message = $message ?: "A GET request to '{$uri}' failed. Got a {$status} code instead.";

            $this->logLatestContent();

            if (method_exists($this, 'handleInternalError')) {
                $this->handleInternalError($message);
            }

            throw new PHPUnitException($message);
        }
    }
378273
protected function setResponseCode()
    {
        if (function_exists('http_status_code')) {
            http_status_code($this->statusCode);
        } else {
            $message = $this->validStatusCodes[$this->statusCode];

            $sapi_type = php_sapi_name();

            if (substr($sapi_type, 0, 3) == 'cgi') {
                $this->headers['Status'] = new Header('Status', $message);
            } else {
                $headerName = "HTTP/1.1 $message";
                $this->headers['Status'] = new Header($headerName);
            }
        }
    }
273338
protected function status($code, lang_string $message) {
        if (array_key_exists($code, $this->statuses)) {
            throw new coding_exception('Status code already defined');
        }
        $this->statuses[$code] = $message;
    }
1106290
protected function setError($code, $message)
    {
        $this->error = new \OtherCode\Rest\Core\Error($code, $message);
    }
1305403
public function setStatusCode($code)
    {
        // set status code
        $this->statusCode = $code;

        // lookup reason phrase by code and set
        $this->setStatusReasonPhrase(HttpProtocol::getStatusReasonPhraseByCode($code));
    }
181514
public function issue()
    {
        // If there is no next URL, just output the headers as expected.
        foreach ($this->headers as $key => $value) {
            header("{$key}: {$value}", true);
        }

        // Output content type.
        if ($this->contentType) {
            header("content-type: {$this->contentType}; charset={$this->encoding}");
        }

        // Output status code.
        $statusMessage = sprintf('%d %s',
            $this->status,
            HttpClient::getStatusCodeMessage($this->status)
        );
        header('Status: ' . $statusMessage);
    }