Skip to content
Scalekit Docs
Talk to an EngineerDashboard

Error handling

Catch Scalekit exceptions from AgentKit calls and handle not-found, auth, and server failures

AgentKit methods throw typed exceptions when the API returns an error. Catch the specific type first, then fall back to the base server exception.

from scalekit.common.exceptions import (
ScalekitNotFoundException,
ScalekitUnauthorizedException,
ScalekitForbiddenException,
ScalekitServerException,
)
try:
account = scalekit_client.actions.get_connected_account(
connection_name="gmail",
identifier="user@example.com",
)
except ScalekitNotFoundException:
# No connected account yet — create one or send the user through OAuth
pass
except ScalekitUnauthorizedException:
# Invalid or expired client credentials / tokens
pass
except ScalekitForbiddenException:
# Caller is authenticated but not allowed for this resource
pass
except ScalekitServerException as e:
# Unexpected API or platform error
print(e.error_code, e.http_status)
ExceptionWhen it is raisedTypical response
ScalekitNotFoundExceptionResource does not exist (connected account, tool, config)Create the resource or return a clear not-found to the user
ScalekitUnauthorizedExceptionMissing or invalid credentialsRefresh tokens or fix client ID/secret
ScalekitForbiddenExceptionAuthenticated but not permittedAdjust scopes, org, or role
ScalekitServerExceptionBase class for Scalekit HTTP/API failuresLog, retry when safe, surface a generic error

ScalekitServerException is the base type. Prefer checking subclasses first so not-found and auth failures get the right UX.