Skip to content

Can not throw error in v2 due to type mismatch #538

@jelhan

Description

@jelhan

I'm trying to upgrade one of my application to v2 but struggling with throwing errors. My code is very much the same as in the documentation:

use Neomerx\JsonApi\Exceptions\JsonApiException;
use CloudCreativity\LaravelJsonApi\Document\Error\Error;

$error = Error::fromArray([
    'title' => 'Payment Required',
    'detail' => $ex->getMessage(),
    'status' => '402',
]);

throw new JsonApiException($error, 402);

But I'm facing an argument type mismatch. It's telling me that Neomerx\JsonApi\Exceptions\JsonApiException::addError() expects an instance of Neomerx\JsonApi\Contracts\Document\ErrorInterface but instance of CloudCreativity\LaravelJsonApi\Document\Error\Error given.

JsonApiException::addError() is called by JsonApiException constructor if the first argument is neither an instance of Neomerx\JsonApi\Exceptions\ErrorCollection nor an array. The first argument provided to the constructor is forwarded: https://github.com/neomerx/json-api/blob/c911b7494496e79f9de72ee40d6a2b791caaf95b/src/Exceptions/JsonApiException.php#L65-L81

I tried to find a test covering it. I found two tests, which are using JsonApiException. But none of them is passing a CloudCreativity\LaravelJsonApi\Document\Error\Error:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions