-
Notifications
You must be signed in to change notification settings - Fork 3
Closed
Description
(new BalanceResource(new Client('test')))->get()->getAmount()
results in the following error:
Seven\Api\Resource\Balance\Balance::__construct(): Argument #1 ($data) must be of type object, string given, called in VENDORPATH/seven.io/api/src/Resource/Balance/BalanceResource.php on line 10
1 VENDORPATH/seven.io/api/src/Resource/Balance/BalanceResource.php(10): Seven\Api\Resource\Balance\Balance->__construct('900')
This is a result of the balance
endpoint returning "900"
(json-encoded error code) and an HTTP 200 OK
Status.
Result 900
is checked here, but before json-decoding, therefore '900' === $res
is false.
Lines 115 to 124 in 5d9a442
if ($error !== '') throw new UnexpectedApiResponseException($error); | |
if (false === $res) throw new UnexpectedApiResponseException($error); | |
if ('900' === $res) throw new InvalidApiKeyException; | |
try { | |
$res = json_decode($res, false, 512, JSON_THROW_ON_ERROR); | |
} catch (Exception) { | |
} | |
if ($isSuccess) return $res; |
Maybe the logic of the following lines should be applied to the $res
variable in encoded and decoded condition as well, to catch other possible errors. Also, the response code perhaps shouldn't be 200
with an invalid API key.
Lines 132 to 138 in 5d9a442
throw match ($code) { | |
900 => new InvalidApiKeyException, | |
901 => new SigningHashVerificationException, | |
902 => new MissingAccessRightsException, | |
903 => new ForbiddenIpException, | |
default => new UnexpectedApiResponseException($error), | |
}; |
Metadata
Metadata
Assignees
Labels
No labels