Skip to content

Add RestException export to main twilio package #1110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Aug 1, 2025

Fixes #1105 by adding RestException to the main package exports, allowing developers to import it directly from 'twilio' instead of using deep imports.

Problem

Previously, developers had to use deep imports to access RestException:

// Old approach - problematic with modern TypeScript configs
import RestException from 'twilio/lib/base/RestException'

This caused issues with modern TypeScript configurations and wasn't intuitive for developers who expected to import it from the main package like other Twilio components.

Solution

Added RestException to the main package exports following the same pattern used by other components like RequestClient:

// Now supported - clean and intuitive
import { RestException } from 'twilio'

// Also works with CommonJS
const { RestException } = require('twilio')

Changes

  • Added RestException import to src/index.ts
  • Added both type and value exports to the TwilioSDK namespace
  • Maintains full TypeScript support with proper type definitions

Usage Examples

Error Handling:

import { RestException } from 'twilio';

try {
  // Twilio API call
} catch (error) {
  if (error instanceof RestException) {
    console.log(`Twilio Error ${error.code}: ${error.message}`);
    console.log(`Status: ${error.status}`);
    console.log(`More info: ${error.moreInfo}`);
  }
}

CommonJS:

const { RestException } = require('twilio');
const exception = new RestException(response);

Validation

  • All existing tests pass (316/316)
  • TypeScript compilation succeeds
  • No breaking changes to existing functionality
  • Follows established export patterns in the codebase

This change provides a better developer experience while maintaining backward compatibility and following the library's existing conventions.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: manisha1997 <28821901+manisha1997@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] @twilio/twilio-node/issues/1105 Raise a PR to introduce this. Add RestException export to main twilio package Aug 1, 2025
@Copilot Copilot AI requested a review from manisha1997 August 1, 2025 12:33
Copilot finished work on behalf of manisha1997 August 1, 2025 12:33
Copy link

sonarqubecloud bot commented Aug 1, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature Request]: Add root RestException export
2 participants