Skip to content

isTwilioRestException

function isTwilioRestException(exception): exception is RestException;

Defined in: lib/exception/twilio-exception.filter.ts:72

Structural (duck-typed) check for a Twilio SDK RestException.

The Twilio SDK is only imported here for its types (import type), so this guard never touches the real RestException class at runtime. That keeps TwilioExceptionFilter working even in setups where the twilio package’s runtime export shape differs (major version drift, duplicated module instances across bundlers, or the class being otherwise unavailable). Anything that merely looks like a Twilio REST error is still handled correctly.

Parameter Type Description
exception unknown Value caught by the filter; may be any thrown value.

exception is RestException

true when exception has the shape of a Twilio RestException.

try {
await twilioService.client.messages.create({ ... });
} catch (error) {
if (isTwilioRestException(error)) {
console.error(error.code, error.moreInfo);
}
}