Skip to content

feat: add CameraErrorCode enum for type-safe error handling#45

Merged
andredestro merged 1 commit intomainfrom
feat/camera-error-codes
Apr 21, 2026
Merged

feat: add CameraErrorCode enum for type-safe error handling#45
andredestro merged 1 commit intomainfrom
feat/camera-error-codes

Conversation

@andredestro
Copy link
Copy Markdown
Contributor

@andredestro andredestro commented Apr 20, 2026

Summary

Adds a CameraErrorCode TypeScript enum that exposes all error codes returned by the Camera plugin, enabling type-safe error handling without relying on raw strings.

Reference #43

What changed

  • Added CameraErrorCode enum to src/definitions.ts with 24 error codes grouped by category (Permissions, Take Photo, Edit Photo, Choose from Gallery, Record Video, Play Video, General)
  • Each value follows the existing OS-PLUG-CAMR-XXXX format already returned in rejected promise payloads
  • Platform-specific codes are annotated with @platform ios or @platform android in JSDoc
  • Automatically exported via the existing export * from './definitions' barrel in src/index.ts

Usage

Before:

camera.getPhoto(...).catch((err) => {
  if (err.code === 'OS-PLUG-CAMR-0003') {
    // handle camera permission denied
  }
});

After:

import { CameraErrorCode } from '@capacitor/camera';

camera.getPhoto(...).catch((err) => {
  if (err.code === CameraErrorCode.CameraPermissionDenied) {
    // handle camera permission denied
  }
});

@andredestro andredestro merged commit 11abcbe into main Apr 21, 2026
8 checks passed
@andredestro andredestro deleted the feat/camera-error-codes branch April 21, 2026 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants