UNPKG

@twilio/voice-react-native-sdk

Version:
27 lines (24 loc) 1.03 kB
import { errorsByCode } from './generated'; import { TwilioError } from './TwilioError'; import { InvalidArgumentError } from './InvalidArgumentError'; /** * Uses the generated error-code map to create the appropriate error. * If the code is "unexpected" such that there is no constructor for that * specific code, this function will default to a generic {@link TwilioError}. * * @param message an error message * @param code a Twilio error code, for example `31209` * * @returns a {@link TwilioError} or appropriate sub-class */ export function constructTwilioError(message, code) { if (typeof message !== 'string') { throw new InvalidArgumentError('The "message" argument is not of type "string".'); } if (typeof code !== 'number') { throw new InvalidArgumentError('The "code" argument is not of type "number".'); } const ErrorClass = errorsByCode.get(code); return typeof ErrorClass !== 'undefined' ? new ErrorClass(message) : new TwilioError(message, code); } //# sourceMappingURL=utility.js.map