fix: Log errors to console if no onError handler is passed

This commit is contained in:
Marc Rousavy 2023-11-18 12:16:52 +01:00
parent c9dbd412be
commit 98a641702c
No known key found for this signature in database
GPG Key ID: 83BEF0F19E8F5321

View File

@ -380,13 +380,16 @@ export class Camera extends React.PureComponent<CameraProps> {
//#region Events (Wrapped to maintain reference equality) //#region Events (Wrapped to maintain reference equality)
private onError(event: NativeSyntheticEvent<OnErrorEvent>): void { private onError(event: NativeSyntheticEvent<OnErrorEvent>): void {
const error = event.nativeEvent
const cause = isErrorWithCause(error.cause) ? error.cause : undefined
// @ts-expect-error We're casting from unknown bridge types to TS unions, I expect it to hopefully work
const cameraError = new CameraRuntimeError(error.code, error.message, cause)
if (this.props.onError != null) { if (this.props.onError != null) {
const error = event.nativeEvent this.props.onError(cameraError)
const cause = isErrorWithCause(error.cause) ? error.cause : undefined } else {
this.props.onError( // User didn't pass an `onError` handler, so just log it to console
// @ts-expect-error We're casting from unknown bridge types to TS unions, I expect it to hopefully work console.error(`Camera.onError(${cameraError.code}): ${cameraError.message}`, cameraError)
new CameraRuntimeError(error.code, error.message, cause),
)
} }
} }