# Camera/Image stream: show error message?

**URL:** <https://community.homey.app/t/camera-image-stream-show-error-message/49252>\
**Category:** Developers\
**Created:** [July 9, 2021, 10:45am UTC](https://community.homey.app/t/camera-image-stream-show-error-message/49252 "2021-07-09T10:45:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [July 9, 2021, 10:45am UTC](https://community.homey.app/t/camera-image-stream-show-error-message/49252/1 "2021-07-09T10:45:26Z")

</div>

I’m extending the Blink app and got struggle with the image recovery.  
The Blink server gives a http error if the camera (http post for creating new snapshot) is busy. In this case I want to abort the image refresh in the Homey app and show a red message “camera is busy”.

I followed the Homey API description and trow an error. But the camera view is still busy with the circeling refresh icon and no message is shown.

The code is:

```
        const _snapshotImage = new Homey.Image();
        _snapshotImage.setStream(async stream => {
            self.log('_registerSnapshotImage() -> setStream -> Capture_snap');
            self._getNewSnapshotUrl()
                .then( 
                     //...get the immage via URL
                    res.body.pipe(stream);
                })
                .catch((error) => {
                    self.log("_registerSnapshotImage Error calling _getNewSnapshotUrl: "+error);
                    throw new Error('Camera is busy');
                });
        _snapshotImage.register()
            .then(() => self.log('_registerSnapshotImage() -> registered'))
            .then(() => self.setCameraImage('snapshot', 'Snapshot', _snapshotImage))
            .catch(self.error);

```

I think it’s similar to the example below “Using a stream”:  
[https://apps-sdk-v2.developer.athom.com/tutorial-Images.html](https://apps-sdk-v2.developer.athom.com/tutorial-Images.html)

Has anyone an example how to deal with errors on image refresh? Many thanks.  
Ronny

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [July 9, 2021, 10:52am UTC](https://community.homey.app/t/camera-image-stream-show-error-message/49252/2 "2021-07-09T10:52:50Z")

</div>

Do you also use the rest of the code as shown in the example, specifically this:

```auto
_snapshotImage.register().catch(console.error);

```

If so, you’re just catching the error and showing it on console, but I don’t think it will be propagated back the the SDK.

You could also try and explicitly destroy the stream:

```auto
…
.catch(error => {
  self.log(…);
  const err = Error('Camera is busy');
  stream.destroy(err);
  throw err;
});

```

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [July 9, 2021, 12:23pm UTC](https://community.homey.app/t/camera-image-stream-show-error-message/49252/3 "2021-07-09T12:23:40Z")

</div>

Hello Robert,

the \_snapshotImage.register() is there. I edited the code above.

The stream.destroy results in an exception and the app is killed.  
Instead, **stream.close( )** is working. One step ahead 🙂

The image refresh ist stopped, but it seems I can’t set an error text. Homey displays the default error caused by the empty stream.

 ![Screenshot_20210709-133821_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/6/9/697072676951250c8c97c207d2276118219d1b1c.jpeg)

It seems, Homey is checking the exception in another way I thought. After throwing the error, Homey tries to get the image again (but then there is stil the http error), and that’s causing a delay until the refresh got his timeout. So invalid\_content\_typüe is not nice, but working for the moment.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [July 9, 2021, 1:24pm UTC](https://community.homey.app/t/camera-image-stream-show-error-message/49252/4 "2021-07-09T13:24:22Z")

</div>

> [@RonnyW](#):
>
> the \_snapshotImage.register() is there. I edited the code above.

Have you tried removing the `.catch()` after the `.register()`?

---

<div class="post-metadata">

**Author:** ![RonnyW](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ronnyw/32/10879_2.png) [@RonnyW](https://community.homey.app/u/RonnyW)\
**Post date:** [July 10, 2021, 11:25am UTC](https://community.homey.app/t/camera-image-stream-show-error-message/49252/5 "2021-07-10T11:25:26Z")

</div>

Yes, for one try. But that`s not the fault. The register( ) doesn`t throw an exeption. Thanks for your help.

I have implemented a way to wait for a updated snapshot URL if the camera is too slow. So I hope this error will not occour in the normal usage.
