Appearance
Errors
Failed requests throw a subclass of Anikeen\Console\Exceptions\ApiException (which extends anikeen/id's ApiException).
| Member | |
|---|---|
status | the HTTP status; 0 when the Console was not reachable |
error | the Console's error code (e.g. owner_only), if any |
getMessage() | the Console's message |
body() | the decoded JSON body of the error response, or null |
isTemporary() | true when it is worth retrying later: unreachable, 5xx or 429 |
Exceptions
| Exception | When |
|---|---|
AuthenticationException | 401, also after a failed refresh: sign the user in again |
ClientNotAllowedException | 401 client_not_allowed: the Console does not accept your app's tokens (not trusted) |
MissingScopeException | 403 missing_scope; scope() names the missing scope |
NotFoundException | 404: no such object, or not in your app team |
AccountConflictException | 409 account_conflict: another Console account uses the user's e-mail address |
ValidationFailedException | 422; errors() per field (e.g. items.0.attributes.location_id), errorFor($field) |
RateLimitException | 429; retryAfter in seconds |
ApiException | everything else, e.g. 403 email_not_verified, 403 owner_only, 409 (deletion protection, suspended), 502 checkout_unavailable |
All live in Anikeen\Console\Exceptions.
Example
php
use Anikeen\Console\Exceptions\ApiException;
use Anikeen\Console\Exceptions\AuthenticationException;
use Anikeen\Console\Exceptions\MissingScopeException;
use Anikeen\Console\Exceptions\RateLimitException;
use Anikeen\Console\Exceptions\ValidationFailedException;
try {
$order = $console->orders($team)->create($items, ['tos_accepted' => true]);
} catch (ValidationFailedException $e) {
return back()->withErrors(['location' => $e->errorFor('items.0.attributes.location_id')]);
} catch (MissingScopeException $e) {
// ask the user to sign in again with $e->scope()
return redirect()->route('login', ['scope' => $e->scope()]);
} catch (AuthenticationException) {
return redirect()->route('login');
} catch (RateLimitException $e) {
return back()->with('error', "Please try again in {$e->retryAfter} seconds.");
} catch (ApiException $e) {
if ($e->isTemporary()) {
// retry later with the same Idempotency-Key ($orders->withIdempotencyKey(...))
}
throw $e;
}A user without any stored token throws anikeen/id's RequestRequiresAuthenticationException before a request is sent.
The underlying API errors are listed on Errors.