/** * Documented MyID result codes. * * The SDK can emit codes beyond these (liveness advice codes such as 3, 14, * 20..28), so never treat this map as exhaustive — always compare against * `error.code` directly rather than assuming one of these values. * * Full list: https://docs.myid.uz/#/ru/embedded?id=javob-kodlar-uz-result_code */ export const MyIdErrorCode = { /** User dismissed the flow. */ USER_CANCELLED: '101', CAMERA_PERMISSION_DENIED: '102', /** Generic SDK or server failure, also used for wrapper-level errors. */ FAILURE: '103', USER_BANNED: '122', } as const; export type MyIdErrorCodeValue = (typeof MyIdErrorCode)[keyof typeof MyIdErrorCode]; /** * Thrown by `start()` for every failure path, including user cancellation. */ export class MyIdError extends Error { /** SDK result code as a string, e.g. `'101'`. */ readonly code: string; constructor(code: string, message: string) { super(message); this.code = code; this.name = 'MyIdError'; // Restores the prototype chain, which is lost when a built-in is // subclassed and the output is down-levelled. Object.setPrototypeOf(this, MyIdError.prototype); } } export function isMyIdError(error: unknown): error is MyIdError { return error instanceof MyIdError; }