Skip to main content

Regula Error Codes

The Regula module handles document capture and OCR processing. When errors occur, they are thrown as ResponseError objects with specific error codes.

Error Structure

All errors follow the ResponseError structure:
interface ResponseError {
  code: string;        // Error code constant
  message: string;     // Human-readable error message
  details?: any;       // Optional additional error details
}

Error Codes

CAMERA_PERMISSION_DENIED

Thrown when the user denies camera permissions or camera access is blocked by the browser. Code: FadSDK.Errors.Regula.CAMERA_PERMISSION_DENIED When it occurs:
  • User explicitly denies camera permission
  • Browser blocks camera access due to security policies
  • Camera is already in use by another application
How to handle:
try {
  const regulaResponse = await FAD_SDK.startRegula(
    CREDENTIALS,
    FadSDK.Constants.Regula.CaptureType.CAMERA_SNAPSHOT,
    idData,
    idPhoto,
    CONFIGURATION
  );
} catch (ex) {
  if (ex.code === FadSDK.Errors.Regula.CAMERA_PERMISSION_DENIED) {
    // Inform user to enable camera permissions
    alert('Camera permission denied. Please enable camera access in your browser settings.');
  }
}
Always check camera permissions before starting the Regula module to provide a better user experience.

ID_PHOTO_NOT_FOUND

Thrown when the face photo cannot be extracted from the ID document. Code: FadSDK.Errors.Regula.ID_PHOTO_NOT_FOUND When it occurs:
  • Document quality is too poor to extract the face photo
  • Document doesn’t contain a visible face photo
  • Lighting conditions prevent photo extraction
  • Document is partially obscured or damaged
How to handle:
try {
  const regulaResponse = await FAD_SDK.startRegula(
    CREDENTIALS,
    FadSDK.Constants.Regula.CaptureType.CAMERA_SNAPSHOT,
    true,  // idData
    true,  // idPhoto - requesting face photo
    CONFIGURATION
  );
} catch (ex) {
  if (ex.code === FadSDK.Errors.Regula.ID_PHOTO_NOT_FOUND) {
    // Prompt user to retry with better lighting/positioning
    alert('Face photo not found on ID. Please ensure good lighting and try again.');
    // Restart the capture process
  }
}
This error only occurs when idPhoto parameter is set to true in the startRegula() call.

OCR_NOT_FOUND

Thrown when OCR (Optical Character Recognition) data cannot be extracted from the document. Code: FadSDK.Errors.Regula.OCR_NOT_FOUND When it occurs:
  • Document text is not readable (blur, glare, poor quality)
  • Document type is not supported for OCR
  • Document is damaged or text is obscured
  • Extreme lighting conditions (too bright or too dark)
How to handle:
try {
  const regulaResponse = await FAD_SDK.startRegula(
    CREDENTIALS,
    FadSDK.Constants.Regula.CaptureType.CAMERA_SNAPSHOT,
    true,  // idData - requesting OCR
    idPhoto,
    CONFIGURATION
  );
  
  // Access OCR data
  console.log(regulaResponse.data.idData.ocr);
} catch (ex) {
  if (ex.code === FadSDK.Errors.Regula.OCR_NOT_FOUND) {
    // Prompt user to retry with better conditions
    alert('Could not read document text. Please reduce glare and ensure clear visibility.');
    // Restart the capture process
  }
}
This error only occurs when idData parameter is set to true in the startRegula() call.

Complete Error Handling Example

import FadSDK from '@fad-producto/fad-sdk';

async function captureDocument() {
  const FAD_SDK = new FadSDK(TOKEN, {
    environment: FadSDK.getFadEnvironments().UATHA
  });

  try {
    const idData = true;
    const idPhoto = true;

    const regulaResponse = await FAD_SDK.startRegula(
      CREDENTIALS,
      FadSDK.Constants.Regula.CaptureType.CAMERA_SNAPSHOT,
      idData,
      idPhoto,
      CONFIGURATION
    );

    // Check if user closed the module
    if (regulaResponse.event === FadSDK.Constants.EventModule.MODULE_CLOSED) {
      console.log('User closed the module');
      return;
    }

    // Process successful response
    console.log('Document captured successfully');
    console.log('Front:', regulaResponse.data.id.front);
    console.log('Back:', regulaResponse.data.id.back);
    console.log('Face photo:', regulaResponse.data.idPhoto);
    console.log('OCR data:', regulaResponse.data.idData.ocr);

  } catch (ex) {
    // Handle specific errors
    if (ex.code === FadSDK.Errors.Regula.CAMERA_PERMISSION_DENIED) {
      alert('Camera permission denied. Please enable camera access.');
    } else if (ex.code === FadSDK.Errors.Regula.ID_PHOTO_NOT_FOUND) {
      alert('Face photo not found. Please try again with better lighting.');
      // Retry logic here
    } else if (ex.code === FadSDK.Errors.Regula.OCR_NOT_FOUND) {
      alert('Could not read document. Please ensure text is clearly visible.');
      // Retry logic here
    } else {
      // Handle unexpected errors
      console.error('Unexpected error:', ex);
      alert(`An error occurred: ${ex.message}`);
    }
  } finally {
    FAD_SDK.end();
  }
}

Best Practices

Error Recovery

Implement retry logic for ID_PHOTO_NOT_FOUND and OCR_NOT_FOUND errors, as these are often temporary issues related to capture conditions.

User Guidance

Provide clear instructions to users when errors occur, especially for camera permissions and document positioning.

Logging

Always log errors for debugging purposes, but avoid exposing sensitive error details to end users.

Build docs developers (and LLMs) love