UNPKG

@snap/camera-kit

Version:
131 lines 5.68 kB
/** * Helper type to extract type generic parameter. */ type ExtractName<P> = P extends NamedError<infer T> ? T : never; /** * All errors are expected to have "Error" suffix. */ type ErrorName = `${string}Error`; type NamedError<Name extends ErrorName> = Error & { name: Name; }; /** * Creates error factory that ensures Error.prototype.name field value. * * NOTE: exported only for unit tests. * * @param name Error name. * @returns Error factory function. * @internal */ export declare function namedError<TError extends NamedError<TName> = never, TName extends ErrorName = ExtractName<TError>>(name: TName): (message: string, cause?: unknown) => TError; export type LegalError = NamedError<"LegalError">; /** @internal */ export declare const legalError: (message: string, cause?: unknown) => LegalError; export type LensContentValidationError = NamedError<"LensContentValidationError">; /** @internal */ export declare const lensContentValidationError: (message: string, cause?: unknown) => LensContentValidationError; export type LensError = NamedError<"LensError">; /** @internal */ export declare const lensError: (message: string, cause?: unknown) => LensError; export type CameraKitSourceError = NamedError<"CameraKitSourceError">; /** @internal */ export declare const cameraKitSourceError: (message: string, cause?: unknown) => CameraKitSourceError; /** * The error triggered when a lens prompts the user to select an image, but the image fails to be successfully delivered * to the lens. */ export type LensImagePickerError = NamedError<"LensImagePickerError">; /** @internal */ export declare const lensImagePickerError: (message: string, cause?: unknown) => LensImagePickerError; export type CacheKeyNotFoundError = NamedError<"CacheKeyNotFoundError">; /** @internal */ export declare const cacheKeyNotFoundError: (message: string, cause?: unknown) => CacheKeyNotFoundError; /** * Thrown by {@link bootstrapCameraKit} if provided configuration is invalid. * * @category Bootstrapping and Configuration */ export type ConfigurationError = NamedError<"ConfigurationError">; /** @internal */ export declare const configurationError: (message: string, cause?: unknown) => ConfigurationError; export type WebGLError = NamedError<"WebGLError">; /** @internal */ export declare const webGLError: (message: string, cause?: unknown) => WebGLError; export type BenchmarkError = NamedError<"BenchmarkError">; /** @internal */ export declare const benchmarkError: (message: string, cause?: unknown) => BenchmarkError; /** * Thrown by {@link bootstrapCameraKit} when the current platform is not supported by CameraKit. * * This can happen if the browser doesn't support a required feature (e.g. WebGL). * * @category Bootstrapping and Configuration */ export type PlatformNotSupportedError = NamedError<"PlatformNotSupportedError">; /** @internal */ export declare const platformNotSupportedError: (message: string, cause?: unknown) => PlatformNotSupportedError; /** * This error occurs if a Lens is unable to continue rendering. * * If this error occurs, Camera Kit automatically removes the Lens from the session. * It's always a good idea to handle this error and update the user experience accordingly. * For example, you could remove the faulty Lens from your Lens selection UI. * * ```ts * cameraKitSession.events.addEventListener('error', ({ detail }) => { * if (detail.error.name === 'LensExecutionError') { * console.log(`Lens ${detail.lens.name} encountered an error and was removed. Please pick a different lens.`) * } * }) * ``` */ export type LensExecutionError = NamedError<"LensExecutionError">; /** @internal */ export declare const lensExecutionError: (message: string, cause?: unknown) => LensExecutionError; /** * This error occurs when a session becomes inoperable. * * It's always a good idea to handle this error and update the user experience accordingly. * For example, you could show a message to a user. * * ```ts * cameraKitSession.events.addEventListener('error', ({ detail }) => { * if (detail.error.name === 'LensAbortError') { * console.log(`Camera Kit encountered an unrecoverable error and became inoperable. Please refresh the page.`) * } * }) * ``` */ export type LensAbortError = NamedError<"LensAbortError">; /** @internal */ export declare const lensAbortError: (message: string, cause?: unknown) => LensAbortError; /** * Error thrown when LensCore asked to store lens data, but CameraKit failed storing that. */ export type PersistentStoreError = NamedError<"PersistentStoreError">; /** @internal */ export declare const persistentStoreError: (message: string, cause?: unknown) => PersistentStoreError; /** * Error thrown when LensCore asked to provide an asset, but CameraKit failed providing that. */ export type LensAssetError = NamedError<"LensAssetError">; /** @internal */ export declare const lensAssetError: (message: string, cause?: unknown) => LensAssetError; /** * Thrown by {@link bootstrapCameraKit} if an error occurs during SDK initialization or while downloading the render * engine WebAssembly. * * @category Bootstrapping and Configuration */ export type BootstrapError = NamedError<"BootstrapError">; /** @internal */ export declare const bootstrapError: (message: string, cause?: unknown) => BootstrapError; /** * Thrown when a method receives an argument with an unexpected value. */ export type ArgumentValidationError = NamedError<"ArgumentValidationError">; /** @internal */ export declare const argumentValidationError: (message: string, cause?: unknown) => ArgumentValidationError; export {}; //# sourceMappingURL=namedErrors.d.ts.map