Skip to main content
The Notion SDK throws four specific error types, all of which extend a base NotionClientErrorBase class. Each error has a unique code property for easy identification.

APIResponseError

Thrown when the Notion API responds with an error. This is the most common error type you’ll encounter.

Properties

  • code: APIErrorCode - The specific error code from the API (see Error Codes)
  • status: number - HTTP status code
  • message: string - Human-readable error message
  • headers: Response.headers - HTTP response headers
  • body: string - Raw response body
  • additional_data?: Record<string, string | string[]> - Additional error context from the API
  • request_id?: string - Notion request ID for support inquiries

Type Guard

Example

RequestTimeoutError

Thrown when a request to the Notion API exceeds the configured timeout (default: 60 seconds).

Properties

  • code: ClientErrorCode.RequestTimeout - Always set to "notionhq_client_request_timeout"
  • message: string - Error message (default: “Request to Notion API has timed out”)

Type Guard

Example

UnknownHTTPResponseError

Thrown when the API responds with an unexpected format or unknown error code. This typically indicates a response that doesn’t match the expected error structure.

Properties

  • code: ClientErrorCode.ResponseError - Always set to "notionhq_client_response_error"
  • status: number - HTTP status code
  • message: string - Error message (default includes status code)
  • headers: Response.headers - HTTP response headers
  • body: string - Raw response body

Type Guard

Example

InvalidPathParameterError

Thrown when a path parameter contains invalid characters that could alter the intended API endpoint, such as path traversal sequences (..).

Properties

  • code: ClientErrorCode.InvalidPathParameter - Always set to "notionhq_client_invalid_path_parameter"
  • message: string - Error message describing the invalid parameter

Type Guard

Example

General Error Handling

isNotionClientError

Type guard to check if an error is any Notion SDK error.
Example:

isHTTPResponseError

Type guard to check if an error is an HTTP response error (has status, headers, and body).
Example:

Error Handling Best Practices

1. Handle Specific Error Codes

2. Log Request IDs for Support

3. Use Type Guards for Type Safety

4. Check Additional Data