Skip to main content

Handling Errors | Web Barcode Scanner

There are various reasons why opening a scanning screen might fail: unsupported browser, permission was denied, camera does not exist etc.

ScanbotSDK tries to attempt to handle these cases as best as possible, however, as hardware access API in the browser is not backwards compatible or future-proof, this is an ongoing challenge. In order to prevent false positives, we keep error handling to a minimum.

If the user has denied camera permission, the Promise for creating a scanner (createDocumentScanner, createBarcodeScanner, createMrzScanner etc.), will be rejected with MediaPermissionError.

If it is an unsupported browser (specifically, mediaDevices are not available), the Promise will be rejected with UnsupportedMediaDevicesError.

If the matching media is not available, the Promise will be rejected with MediaNotAvailableError.

The Promise will be rejected with LicenseError when a client calls any of the Scanbot SDK functions while having a license error.

If the encountered error is not one of the errors above and not specified in scanner specific documentation pages, it will be rejected with UnknownError.

Promise rejections means you should try and catch when starting the scanners. If a scanner throws an error (camera permission etc.) while starting, the error can be caught as follows:

try {
documentScanner = await scanbotSDK.createDocumentScanner(config);
} catch (error) {
// Handle cases where scanner could not be opened
console.log(error.name) // Console log may be UnsupportedMediaDevicesError, MediaPermissionError, ...
}

If a scanner throws an error after being successfully started, it can be caught via onError callback in the configuration:

const config = {
containerId: containerId,
onError: (error) => {
// Action taken
},
...
};

There is no internal and continuous check for invalid or expired license. You should always check this yourself via await scanbotSDK.getLicenseInfo().

Want to scan longer than one minute?

Generate a free trial license to test the Scanbot SDK thoroughly.

Get your free Trial License

What do you think of this documentation?