> For the complete documentation index, see [llms.txt](https://docs.facephi.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.facephi.com/docs.facephi-en/sdks/sdk-web/componentes/selphid-documentos/resultados.md).

# Results

On this page we will explain the different possibilities for finishing the widget capture process.

Every detail of each event (attributes, data...) has been specified on the page of ([events](/docs.facephi-en/sdks/sdk-web/componentes/selphid-documentos/eventos.md)).

## Success stories

### Successful capture and extraction

At the moment the document capture succeeds, the extracted results will be provided in the event `extractionFinish` ([link](/docs.facephi-en/sdks/sdk-web/componentes/selphid-documentos/eventos/extractionfinish.md)).

{% hint style="info" %}
Once this event is emitted, the logic for loading the next view or widget should be implemented, adapting it to the application context.
{% endhint %}

Here is an example:

```typescript
import { type ExtractionFinishEvent } from "@facephi/selphid-web-component"

const selphidWidget = document.querySelector('facephi-selphid-widget');
selphidWidget.addEventListener('extractionFinish', onExtractionFinish);

function onExtractionFinish(event: CustomEvent<ExtractionFinishEvent>) {
  const extractionFinishDetail = event.detail.detail;
  console.log('extractionFinish:', extractionFinishDetail);

  // Procesar resultados en el backend
  saveResults(extractionFinishDetail.result.images.frontDocument, extractionFinishDetail.result.images.backDocument);

  // Cargar el siguiente widget o vista
  loadSelphiWidget();
}
```

***

## Error cases

It is recommended to control the possible errors that may occur when processing the obtained data to avoid internal failures, incorrect widget use, or brute force attacks.

### Error codes

The widget will throw an exception if any usage or internal error occurs.

Exceptions can be of two types:

* Terminal exception: Error that will be thrown when the widget cannot continue executing. These errors can occur in incorrect environments or configurations.
* Extraction exception: Error that will be thrown during the capture or extraction flow. These errors allow the widget flow to be retried, since they are due to incorrect use of the widget by the user.

<table><thead><tr><th width="254.75390625">Error</th><th width="97.01171875">Code</th><th>Description</th></tr></thead><tbody><tr><td><strong>Terminal exceptions</strong></td><td></td><td></td></tr><tr><td>AndroidWebViewBehaviour</td><td>SPD_318</td><td>Error produced after running the component in a WebView in an Android environment.</td></tr><tr><td>UnknownInternalError</td><td>SPD_329</td><td>Internal error in the widget. If the error persists, it will be necessary to contact the Facephi support team</td></tr><tr><td>CameraHardwareError</td><td>SPD_305</td><td>Error produced while accessing the device's cameras.</td></tr><tr><td>PermissionsDenied</td><td>SPD_332</td><td>Error generated by not allowing the necessary permissions for widget execution.</td></tr><tr><td>CameraPermissionDenied</td><td>SPD_301</td><td>Error because permission was not granted to use the device's camera(s).</td></tr><tr><td>MicrophonePermissionDenied</td><td>SPD_319</td><td>Error because permission was not granted to use the device's microphone(s).</td></tr><tr><td>SettingsError</td><td>SPD_320</td><td>Error produced by an incorrect configuration.</td></tr><tr><td>BrowserApiNotCompatible</td><td>SPD_321</td><td>Error produced by an unsupported browser.</td></tr><tr><td><strong>Extraction exceptions</strong></td><td></td><td></td></tr><tr><td>ErrorTimeout</td><td>SPD_001</td><td>Error generated after exceeding the time limit set for extraction.</td></tr></tbody></table>

***

### Time limit exceeded during document capture

With the events `extractionTimeout`([link](/docs.facephi-en/sdks/sdk-web/componentes/selphid-documentos/eventos/extractiontimeout.md)) and `timeoutErrorButtonClick`([link](/docs.facephi-en/sdks/sdk-web/componentes/selphid-documentos/eventos/timeouterrorbuttonclick.md)) it is possible to control when the user exceeds the set time or the attempts used.

Here is an example:

```typescript
import { type ExtractionTimeoutEvent, type TimeoutButtonClickEvent } from "@facephi/selphid-web-component";

const selphidWidget = document.querySelector('facephi-selphid-widget');
selphidWidget.addEventListener('extractionTimeout', onErrorTimeout);
selphidWidget.addEventListener('timeoutErrorButtonClick', onTimeoutButtonClick);
let userRetries = 0;

// El usuario no ha completado la extracción dentro del tiempo permitido
const onExtractionTimeout = (event: CustomEvent<ExtractionTimeoutEvent>) => {
  if (userRetries >= 3) {
    // Redirigir al usuario a una vista de error
    showRetriesExceededView();
  }
}

// El usuario ha hecho clic en el botón para reintentar la extracción en la vista de tiempo de espera del widget
const onTimeoutButtonClick = (event: CustomEvent<TimeoutButtonClickEvent>) => {
  userRetries++;
}
```

***

### Capture attempts exhausted

As an alternative to the manual count in the previous section, the property [maxAttempts](/docs.facephi-en/sdks/sdk-web/componentes/selphid-documentos/propiedades/maxattempts.md) delegates the attempt limit to the widget itself. When they are exhausted, the widget stops retrying and emits `maxAttemptsExceeded` ([link](/docs.facephi-en/sdks/sdk-web/componentes/selphid-documentos/eventos/maxattemptsexceeded.md)).

Here is an example:

```typescript
import { type MaxAttemptsExceededEvent } from "@facephi/selphid-web-component";

const selphidWidget = document.querySelector('facephi-selphid-widget');
selphidWidget.maxAttempts = 3;
selphidWidget.addEventListener('maxAttemptsExceeded', onMaxAttemptsExceeded);

// El usuario ha consumido todos los intentos de captura permitidos
function onMaxAttemptsExceeded(event: CustomEvent<MaxAttemptsExceededEvent>) {
  const detail = event.detail.detail;
  console.log('maxAttemptsExceeded:', detail.message);

  // Redirigir al usuario a una vista de error
  showRetriesExceededView();
}
```

***

### The user closes the widget before document capture

This event is emitted when the user clicks the widget exit icon to cancel the extraction process. Once the button is pressed, the widget will close.

Code example

```typescript
import { type UserCancelEvent } from "@facephi/selphid-web-component";

const selphidWidget = document.querySelector('facephi-selphid-widget');
selphidWidget.addEventListener('userCancel', handleUserCancel);

// El usuario ha hecho clic en el icono de salida del widget para cancelar el proceso de extracción
function handleUserCancel(event: CustomEvent<UserCancelEvent>) {
  // Redirigir al usuario a la página principal del sitio web
  goLandingPage();
}
```

***

### Terminal exceptions during the Widget lifecycle

This event is emitted when a system failure is detected. It can be used to identify and filter different types of errors found during the capture process.

Code example:

```typescript
import { type ExceptionCapturedEvent, type ErrorTimeoutEvent } from "@facephi/selphid-web-component";

const selphidWidget = document.querySelector('facephi-selphid-widget');
selphidWidget.addEventListener('exceptionCaptured', handleExceptionCaptured);
selphidWidget.addEventListener('errorTimeout', handleErrorTimeout);

// Se detecta un mal funcionamiento y el widget se ha detenido
function handleExceptionCaptured(event: CustomEvent<ExceptionCapturedEvent>) {
  const exceptionDetail = event.detail.detail;
  console.error('Widget Exception:', exceptionDetail.exceptionType);
}

// Se ha alcanzado el tiempo establecido en la propiedad `errorTimeout`
function handleErrorTimeout(event: CustomEvent<ErrorTimeoutEvent>) {
  const errorTimeoutDetail = event.detail.detail;
  // Redirigir al usuario a una vista de error
  showErrorView(errorTimeoutDetail.exceptionType);
}
```

***
