Update Errors/Formats docs

This commit is contained in:
Marc Rousavy 2021-03-04 12:04:39 +01:00
parent e6397531ed
commit 8abeef4b25
2 changed files with 12 additions and 3 deletions

View File

@ -10,7 +10,7 @@ sidebar_label: Camera Errors
## Why?
Since the Camera library is quite big, there is a lot that can "go wrong". The react-native-vision-camera library provides thoroughly typed errors to help you quickly identify the cause and fix the problem.
Since the Camera library is quite big, there is a lot that can "go wrong". The VisionCamera library provides thoroughly typed errors to help you quickly identify the cause and fix the problem.
```ts
switch (error.code) {
@ -47,6 +47,10 @@ The `CameraError` type is a baseclass type for all other errors and provides the
* `cause.stacktrace?`: A native Java stacktrace for the cause. (Android only)
* `cause.cause?`: The cause that caused this cause. (Recursive) (Optional)
:::note
See [the `CameraError.ts` file](https://github.com/cuvent/react-native-vision-camera/blob/main/src/CameraError.ts) for a list of all possible error codes
:::
### Runtime Errors
The `CameraRuntimeError` represents any kind of error that occured while mounting the Camera view, or an error that occured during the runtime.
@ -59,7 +63,7 @@ function App() {
console.error(error)
}, [])
return <Camera ref={camera} {...cameraProps} />
return <Camera onError={onError} {...cameraProps} />
}
```
@ -71,6 +75,7 @@ The `CameraCaptureError` represents any kind of error that occured only while ca
function App() {
const camera = useRef<Camera>(null)
// called when the user presses a "capture" button
const onPress = useCallback(() => {
try {
const photo = await camera.current.takePhoto()

View File

@ -16,7 +16,7 @@ Each camera device (see [Camera Devices](./DEVICES.md)) provides a number of cap
If you don't want to specify the best format for your camera device, you don't have to. The Camera _automatically chooses the best matching format_ for the current camera device. This is why the Camera's `format` property is _optional_.
If you don't want to do a lot of filtering, but still want to let the camera know what your intentions are, you can use the Camera's `preset` property. (See the [CameraPreset.ts](https://github.com/cuvent/react-native-vision-camera/blob/main/src/CameraPreset.ts) type for more information about presets)
If you don't want to do a lot of filtering, but still want to let the camera know what your intentions are, you can use the Camera's `preset` property.
For example, use the `'medium'` preset if you want to create a video-chat application that shouldn't excessively use mobile data:
@ -36,6 +36,10 @@ function App() {
}
```
:::note
See the [CameraPreset.ts](https://github.com/cuvent/react-native-vision-camera/blob/main/src/CameraPreset.ts) type for more information about presets
:::
### What you need to know about cameras
To understand a bit more about camera formats, you first need to understand a few "general camera basics":