NotionClientError and include specific error codes.
Error Types
The SDK throws four distinct error types:APIResponseError
Thrown when the Notion API returns an error response with a recognized error code.The error code returned by the API (e.g.,
unauthorized, object_not_found).HTTP status code (e.g., 404, 429, 500).
Human-readable error message from the API.
Response headers, including
retry-after for rate limit errors.Raw response body text.
Notion’s request ID for debugging. Include this when contacting support.
Additional context from validation errors.
RequestTimeoutError
Thrown when a request exceeds the configured timeout (default 60 seconds).Always
"notionhq_client_request_timeout".UnknownHTTPResponseError
Thrown when the API returns an error response that doesn’t match the expected error format.Always
"notionhq_client_response_error".HTTP status code.
Raw response body text.
InvalidPathParameterError
Thrown when a path parameter contains path traversal sequences (e.g.,..) that could alter the request path.
Always
"notionhq_client_invalid_path_parameter".Error Codes
APIErrorCode
Error codes returned by the Notion API:ClientErrorCode
Error codes generated by the SDK client:Type Guards
Use type guards to narrow error types:isNotionClientError
Check if an error is any SDK error:isHTTPResponseError
Check if an error is an HTTP response error (has status, headers, body):Specific Error Type Guards
Each error class has its own type guard:Common Error Patterns
Handle Rate Limits
The SDK automatically retries rate limit errors (429) with exponential back-off. See Retries for details.
Handle Missing Resources
Handle Validation Errors
Retry on Server Errors
The SDK automatically retries server errors (500, 503) for idempotent methods (GET, DELETE). See Retries.
Log Request IDs
Always logrequest_id for debugging and support:
Error Handling Best Practices
- Always use type guards - Don’t assume error types
- Log request IDs - Essential for debugging with Notion support
- Handle specific codes - Match on
error.codefor different behaviors - Let retries work - The SDK auto-retries transient errors
- Validate inputs - Check IDs and parameters before making requests