Flarum\Api\ErrorHandler::handle PHP Méthode

handle() public méthode

public handle ( Exception $e ) : JsonApiResponse
$e Exception
Résultat JsonApiResponse
    public function handle(Exception $e)
    {
        $response = $this->errorHandler->handle($e);
        $document = new Document();
        $document->setErrors($response->getErrors());
        return new JsonApiResponse($document, $response->getStatus());
    }

Usage Example

Exemple #1
0
 /**
  * Execute the given API action class, pass the input and return its response.
  *
  * @param string|ControllerInterface $controller
  * @param User $actor
  * @param array $queryParams
  * @param array $body
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function send($controller, User $actor, array $queryParams = [], array $body = [])
 {
     $request = ServerRequestFactory::fromGlobals(null, $queryParams, $body)->withAttribute('actor', $actor);
     if (is_string($controller)) {
         $controller = $this->container->make($controller);
     }
     if (!$controller instanceof ControllerInterface) {
         throw new InvalidArgumentException('Endpoint must be an instance of ' . ControllerInterface::class);
     }
     try {
         return $controller->handle($request);
     } catch (Exception $e) {
         return $this->errorHandler->handle($e);
     }
 }
All Usage Examples Of Flarum\Api\ErrorHandler::handle