Every exception the SDK raises derives from scute.ScuteError, except ValueError for bad arguments.
from scute import APIError, ConfigurationError, ConnectionError, InvalidToken, ScuteErrorscute.ConnectionError is the SDK's own class and shadows Python's built-in ConnectionError when imported by name. Import it as from scute import ConnectionError as ScuteConnectionError if you need both.
Hierarchy#
| Class | Base | Raised when |
|---|---|---|
| ScuteError | Exception | Base for all of the below. |
| APIError | ScuteError | Scute answered with a status outside 2xx. |
| ConnectionError | ScuteError | Scute could not be reached, after one retry for idempotent calls. |
| ConfigurationError | ScuteError | No app id at construction, no secret for a secret-key call, or no credentials for a call. |
| InvalidToken | ScuteError | An access token is not a live session of this app. |
APIError#
| Attribute | Type | Value |
|---|---|---|
| str(e) | str | The API's error, else its say, else Scute answered <status> |
| status | int or None | HTTP status |
| code | str or None | The API's error_code, for example already_merged |
| body | Any | The decoded JSON body, or None |
try: scute.users.merge(user_id, old_id)except APIError as e: if e.status == 422 and e.code == "already_merged": ... else: raiseSee the API reference for status codes and error codes.
InvalidToken#
Raised by scute.tokens.verify. e.reason is one of missing, malformed, algorithm, signature, expired, wrong_app, not_a_user, revoked. See Verify tokens.
try: session = scute.tokens.verify(token)except InvalidToken as e: return {"error": str(e), "reason": e.reason}, 401verify can also raise ConnectionError or APIError when it cannot read the app's keys, or when remote=True and Scute answers with a status other than 401, 403 or 404. Treat those as "could not check", not as an invalid token.
ConfigurationError#
| Message | Cause |
|---|---|
| Scute needs an app id: pass app_id or set SCUTE_APP_ID | Scute() with no app id. |
| This call needs the app's secret key: pass secret or set SCUTE_SECRET | A secret-key call on a client without a secret. |
| Harness needs agent: the agent's slug in Scute | Harness(agent=""). |
ValueError#
- client_ip (constructor, with_client_ip, request) is not one IPv4 or IPv6 address.
- authz.check_batch got more than 100 checks.
Framework responses#
The FastAPI and Flask helpers turn errors into responses:
| Case | Status | Body |
|---|---|---|
| InvalidToken | 401 | error, reason |
| Decision is not a plain allow | 403 | error, decision |
In FastAPI the body is under detail. APIError and ConnectionError from the check are not caught; they reach your app's error handling.