Skip to content

Commit 1f4f26c

Browse files
committed
feat: named error when Stream API not supported
1 parent d9fff6f commit 1f4f26c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/misc/camera.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { StreamApiNotSupportedError } from './errors.js'
12
import { imageDataFromVideo } from './image-data.js'
23
import { hasFired } from './promisify.js'
34

@@ -22,7 +23,7 @@ class Camera {
2223

2324
export default async function (constraints, videoEl) {
2425
if (!(navigator.mediaDevices && navigator.mediaDevices.getUserMedia)) {
25-
throw new Error('WebRTC API not supported in this browser')
26+
throw new StreamApiNotSupportedError()
2627
}
2728

2829
const stream = await navigator.mediaDevices.getUserMedia(constraints)

src/misc/errors.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,11 @@ export class DropImageDecodeError extends Error {
1414
this.name = 'DropImageDecodeError'
1515
}
1616
}
17+
18+
export class StreamApiNotSupportedError extends Error {
19+
constructor () {
20+
super('this browser has no Stream API support')
21+
22+
this.name = 'StreamApiNotSupportedError'
23+
}
24+
}

0 commit comments

Comments
 (0)