Returns 404 / Resource not found response.

@param int  $code
@param null $message

@return \Illuminate\Http\JsonResponse
348156
public function respondNotFound($code = ApiResponse::CODE_NOT_FOUND, $message = null): JsonResponse
    {
        return $this->setStatusCode(IlluminateResponse::HTTP_NOT_FOUND)
            ->respondWithError($code, $message);
    }
956509
public function error( $code = 404, $msg = "Resource not found" )
	{
		$request = HttpFactory::i()->request();

		if ( $request->ajax() || $request->wantsJson() )
			return new JsonResponse( ['error' => $msg] );
		else
			return new Response( Redirect::back()->withInput( $request->input() )->withErrors( ['error' => $msg] ) );
	}
670841
public function error($errorCode = null, int $statusCode = null, $message = null):JsonResponse
    {
        if ($exception = config("responder.exceptions.$errorCode")) {
            if (class_exists($exception)) {
                throw new $exception();
            }
        }

        return $this->errorResponse->setError($errorCode, $message)->respond($statusCode);
    }
684602
public static function respond($status = 404, $message = '') {
        http_response_code($status);
        if (Request::isAjaxRequest()) {
            @header('ajax: 1');
            Response::getInstance()->output(['message' => $message ? $message : __('error occurred')]);
            Response::getInstance()->close();
        } else {
            if ($status == 404) {
                $data ['message'] = $message;
                $view             = template('404.tpl', $data);
            } else if ($status == 403) {
                $data ['message'] = $message;
                $view             = template('403.tpl', $data);
            } else if ($status == 500) {
                $data ['message'] = $message;
                $view             = template('500.tpl', $data);
            } else if ($status == 503) {
                $data ['message'] = $message;
                $view             = template('503.tpl', $data);
            } else if ($message) {
                if (is_array($message)) {
                    $view = new JsonView($message);
                } else {
                    $view = new SimpleView($message);
                }
            } else {
                $view = null;
            }
            if ($view) {
                Response::getInstance()->output($view);
                Response::getInstance()->close();
            }
        }
        exit (1);
    }
656241
public function respondForbidden($message = null): JsonResponse
    {
        return $this->setStatusCode(IlluminateResponse::HTTP_FORBIDDEN)
            ->respondWithError(ApiResponse::CODE_FORBIDDEN, $message);
    }
224790
public static function get($code, $data=null) {
    self::predefine();
    if (defined($code)) {
      $def = unserialize(constant($code));
      $error = new ApplicationError($def[0], $def[1], $def[2], $def[3], $data);
      return $error;
    }
    else {
      throw new IllegalArgumentException("The error code '".$code."' is not defined");
    }
  }
448024
public function respondCreated($code = ApiResponse::CODE_SUCCESS, array $data = [], $message = null): JsonResponse
    {
        return $this->setStatusCode(IlluminateResponse::HTTP_CREATED)->respond([
            'status' => [
                'type' => 'success',
                'message' => $this->getDefaultMessage($code, $message),
                'code' => $code,
                'http_code' => $this->getStatusCode(),
            ],
            'data' => $data,
        ]);
    }
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);
    }
1070512
protected function respondNotFound($message = '')
    {
        if (empty($message))
        {
            $message = ucfirst($this->baseClass).' does not exist';
        }

        return $this->respondWithError($message, 404);
    }
620167
public function postSignup($code = null)
    {
        if ($code === null) {
            throw new NotFoundHttpException();
        }

        $invite = Invite::where('code', '=', $code)->first();

        if (!$invite || $invite->is_claimed) {
            throw new BadRequestHttpException();
        }

        try {
            execute(new SignupUserCommand(
                Binput::get('username'),
                Binput::get('password'),
                Binput::get('email'),
                User::LEVEL_USER
            ));
        } catch (ValidationException $e) {
            return cachet_redirect('signup.invite', [$invite->code])
                ->withInput(Binput::except('password'))
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('cachet.signup.failure')))
                ->withErrors($e->getMessageBag());
        }

        execute(new ClaimInviteCommand($invite));

        return cachet_redirect('status-page')
            ->withSuccess(sprintf('<strong>%s</strong> %s', trans('dashboard.notifications.awesome'), trans('cachet.signup.success')));
    }
269426
public function error( $message, $code = null, $data = null )
    {
        if ( null === $code && isset( $this->errorCodes[$message] ) )
        {
            $code = $this->errorCodes[$message];
        }

        return $this->getResponse( 'error', (object) array(
            'code'      => $code,
            'message'   => $message,
            'data'      => $data,
        ) );
    }
802749
protected function buildErrorResponse($error, $code = null)
    {
        if ($code !== null && (!is_int($code) || $code < 400)) {
            $code = null;
        }
        if (is_object($error)) {
            if ($error instanceof AccessDeniedException) {
                $error = $error->getMessage();
                if ($code === null) {
                    $code = Response::HTTP_UNAUTHORIZED;
                }
            } elseif ($error instanceof UserMessageException) {
                if ($error->getCode() >= 400) {
                    $code = $error->getCode();
                }
                $error = $error->getMessage();
            } elseif ($error instanceof Exception || $error instanceof Throwable) {
                $error = t('An unexpected error occurred');
            } elseif (is_callable([$error, '__toString'])) {
                $error = (string) $error;
            } else {
                $error = get_class($error);
            }
        }
        if ($code === null) {
            $code = Response::HTTP_INTERNAL_SERVER_ERROR;
        }

        return $this->getResponseFactory()->create(
            $error,
            $code,
            [
                'Content-Type' => 'text/plain; charset=UTF-8',
            ]
        );
    }
295643
public function jsonError($errorCode, $errorMessage = null)
    {
        // Build error from message
        $error = [
            'type' => 'error',
            'code' => $errorCode,
        ];
        if ($errorMessage) {
            $error['value'] = $errorMessage;
        }

        // Support explicit error handling with status = error, or generic message handling
        // with a message of type = error
        $result = [
            'status' => 'error',
            'errors' => [$error]
        ];
        $response = HTTPResponse::create(json_encode($result), $errorCode)
            ->addHeader('Content-Type', 'application/json');

        // Call a handler method such as onBeforeHTTPError404
        $this->extend("onBeforeJSONError{$errorCode}", $request, $response);

        // Call a handler method such as onBeforeHTTPError, passing 404 as the first arg
        $this->extend('onBeforeJSONError', $errorCode, $request, $response);

        // Throw a new exception
        throw new HTTPResponse_Exception($response);
    }
912034
public function get($code = null)
    {
        try {
            return $this->findFileObject($code)->output('inline', true);
        }
        catch (Exception $ex) {}

        return Response::make(View::make('backend::404'), 404);
    }
171304
public static function message($code)
    {
        if (array_key_exists($code, self::$messages)) {
            return self::$messages[$code];
        }

        return null;
    }
773570
public function display(Exception $exception, $code)
    {
        // Collect some info about the exception.
        $info = $this->info($code, $exception);

        // Is the current request an AJAX request?
        if ((boolean)($this->request instanceof Request && $this->request->wantsJson()) == true) {
            $json_object = (object)[ 'error' => [
                'type'    => 'Exception',
                'message' => $info['message'],
            ] ];

            return JsonResponse::create($json_object, $code);
        }

        // For model-not-found, use 404 errors.
        if ($exception instanceof ModelNotFoundException) {
            $code = 404;
        }

        // If there is a custom view, use that.
        if ($this->view->exists("errors.{$code}")) {
            return $this->view->make("errors.{$code}", $info)->render();
        }

        // If the configured default error view (or errors.error) exists, render that.
        if (($errorview = $this->config->get('view.error', 'errors.error')) && $this->view->exists($errorview)) {
            return $this->view->make($errorview, $info)->render();
        }

        // Last resort: simply show the error code and message.
        return new Response($this->getFallbackDisplay($code, $info['name'], $info['message']), $code);
    }
1169265
public function json($code, $msg = '', $data = null) {
        $result = json_encode(['code' => $code, 'msg' => $msg, 'data' => $data]);
        $this->contentType(self::TYPE_JSON);
        $this->_response->end($result);
    }