Working with device error codes in App Cloud

Whenever you interact with native device capabilities, be prepared to handle errors. Device functions return an error code whenever things don't go according to plan. For example, when scanning a QR code:

bc.device.getQRCode(
    function (data) {
        // do stuff
    },
    function (error) {
        if (error.errorCode === bc.device.codes.CAMERA_UNAVAILABLE) {
            bc.device.alert("Oops! This feature requires a camera.");
        }
        // etc.
    }
);

In the above example, I'm displaying a user-friendly message if the camera is unavailable for any reason.

If you make a lot of device calls, you should consider writing a generic function to translate error codes into user-friendly messages that make sense throughout your app.

See all the error codes in the App Cloud API docs.

p.s. Get more tips and tricks (and share your own) by joining the Brightcove App Cloud discussion group on Google.