Skip to main content
Robust error handling is essential for building reliable applications with the Narrative SDK. This guide covers common error types and patterns for handling them.

Prerequisites

Error types

HTTP errors

The SDK throws errors for HTTP response codes indicating failures:

Network errors

Connection issues throw standard JavaScript errors:
  • Connection timeout
  • DNS resolution failure
  • Network unreachable

Validation errors

Query or data validation failures return detailed error messages:
  • NQL syntax errors
  • Schema validation failures
  • Invalid parameter values

Basic error handling

Wrap SDK calls in try-catch blocks:

Handling specific errors

Check the error status for specific handling:

Rate limiting

Handle rate limits with exponential backoff:

Query error handling

NQL queries can fail for various reasons:

Validating before execution

Catch syntax errors before running expensive queries:

Creating an error wrapper

Build a reusable error handler:

Logging errors

Implement structured error logging:

Graceful degradation

Provide fallbacks when services are unavailable:

Best practices

Troubleshooting

Authentication

Configure authentication properly

API Keys

Manage API keys and permissions

Tracking Jobs

Handle async operation errors

SDK Reference

Complete SDK documentation