TwilioExceptionFilter
Defined in: lib/exception/twilio-exception.filter.ts:157
Maps Twilio SDK RestException errors to Nest HTTP responses, preserving
the original HTTP status, Twilio error code, message, moreInfo link,
and details payload as a TwilioErrorResponse JSON body.
Uses @Catch() (no argument) so it can be registered globally without a
hard runtime dependency on the Twilio SDK’s RestException class. It
recognizes Twilio errors structurally via isTwilioRestException
(see that function’s docs for why). Any exception that isn’t a Twilio
RestException is delegated to Nest’s default handling via
BaseExceptionFilter, so registering this filter globally never
swallows unrelated errors.
Examples
Section titled “Examples”Per-route registration
import { UseFilters } from '@nestjs/common';import { TwilioExceptionFilter } from 'nestjs-twilio';
@Controller('sms')@UseFilters(TwilioExceptionFilter)export class SmsController { constructor(@InjectTwilio() private readonly twilio: TwilioService) {}
@Post() send() { return this.twilio.client.messages.create({ ... }); }}Global registration via useGlobalFilters
import { HttpAdapterHost } from '@nestjs/core';import { TwilioExceptionFilter } from 'nestjs-twilio';
const app = await NestFactory.create(AppModule);const { httpAdapter } = app.get(HttpAdapterHost);app.useGlobalFilters(new TwilioExceptionFilter(httpAdapter));await app.listen(3000);Global registration via the APP_FILTER provider
import { APP_FILTER } from '@nestjs/core';import { TwilioExceptionFilter } from 'nestjs-twilio';
@Module({ providers: [{ provide: APP_FILTER, useClass: TwilioExceptionFilter }],})export class AppModule {}Extends
Section titled “Extends”BaseExceptionFilter<unknown>
Implements
Section titled “Implements”ExceptionFilter<RestException>
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new TwilioExceptionFilter(applicationRef?): TwilioExceptionFilter;Defined in: node_modules/.pnpm/@nestjs+core@12.0.4_@nestjs+common@12.0.4_reflect-metadata@0.2.2_rxjs@7.8.2_supports-co_0d6aef3296214b44da550531eb925767/node_modules/@nestjs/core/exceptions/base-exception-filter.d.ts:8
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
applicationRef? |
HttpServer<any, any, any> |
Returns
Section titled “Returns”TwilioExceptionFilter
Inherited from
Section titled “Inherited from”BaseExceptionFilter<unknown>.constructorMethods
Section titled “Methods”catch()
Section titled “catch()”catch(exception, host): void;Defined in: lib/exception/twilio-exception.filter.ts:161
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
exception |
unknown |
host |
ArgumentsHost |
Returns
Section titled “Returns”void
Implementation of
Section titled “Implementation of”ExceptionFilter.catchOverrides
Section titled “Overrides”BaseExceptionFilter.catchhandleUnknownError()
Section titled “handleUnknownError()”handleUnknownError( exception, host, applicationRef): void;Defined in: node_modules/.pnpm/@nestjs+core@12.0.4_@nestjs+common@12.0.4_reflect-metadata@0.2.2_rxjs@7.8.2_supports-co_0d6aef3296214b44da550531eb925767/node_modules/@nestjs/core/exceptions/base-exception-filter.d.ts:10
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
exception |
unknown |
host |
ArgumentsHost |
applicationRef |
| HttpServer<any, any, any> | AbstractHttpAdapter<any, any, any> |
Returns
Section titled “Returns”void
Inherited from
Section titled “Inherited from”BaseExceptionFilter.handleUnknownErrorisExceptionObject()
Section titled “isExceptionObject()”isExceptionObject(err): err is Error;Defined in: node_modules/.pnpm/@nestjs+core@12.0.4_@nestjs+common@12.0.4_reflect-metadata@0.2.2_rxjs@7.8.2_supports-co_0d6aef3296214b44da550531eb925767/node_modules/@nestjs/core/exceptions/base-exception-filter.d.ts:11
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
err |
any |
Returns
Section titled “Returns”err is Error
Inherited from
Section titled “Inherited from”BaseExceptionFilter.isExceptionObjectisHttpError()
Section titled “isHttpError()”isHttpError(err): err is { message: string; statusCode: number };Defined in: node_modules/.pnpm/@nestjs+core@12.0.4_@nestjs+common@12.0.4_reflect-metadata@0.2.2_rxjs@7.8.2_supports-co_0d6aef3296214b44da550531eb925767/node_modules/@nestjs/core/exceptions/base-exception-filter.d.ts:16
Checks if the thrown error is a FastifyError or comes from the “http-errors” library.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
err |
any |
error object |
Returns
Section titled “Returns”err is { message: string; statusCode: number }
Inherited from
Section titled “Inherited from”BaseExceptionFilter.isHttpError