-
Notifications
You must be signed in to change notification settings - Fork 106
Description
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:
- In
tests/lib/Integration/Issue67/Schema.phpan empty array is passed toJsonApiException.throw new JsonApiException([], 500); - In
ErrorsTest::testUnexpectedJsonApiExceptionan instance ofNeomerx\JsonApi\Document\Erroris passed:use Neomerx\JsonApi\Document\Error; throw new JsonApiException(new Error(null, null, 422, null, null, 'My foobar error message.'), 418);