fix: Catch insufficient-storage errors (#2422)

* fix: Catch `insufficient-storage` errors

* feat: Implement `insufficient-storage` error for Android

* fix: Catch insufficient storage error also on takePhoto android
This commit is contained in:
Marc Rousavy
2024-01-24 11:48:38 +01:00
committed by GitHub
parent 7894779094
commit b1fa06514f
10 changed files with 59 additions and 14 deletions

View File

@@ -180,6 +180,7 @@ enum CaptureError {
case videoNotEnabled
case photoNotEnabled
case aborted
case insufficientStorage
case unknown(message: String? = nil)
var code: String {
@@ -198,6 +199,8 @@ enum CaptureError {
return "video-not-enabled"
case .photoNotEnabled:
return "photo-not-enabled"
case .insufficientStorage:
return "insufficient-storage"
case .aborted:
return "aborted"
case .unknown:
@@ -223,6 +226,8 @@ enum CaptureError {
return "Photo capture is disabled! Pass `photo={true}` to enable photo capture."
case .aborted:
return "The capture has been stopped before any input data arrived."
case .insufficientStorage:
return "There is not enough storage space available."
case let .unknown(message: message):
return message ?? "An unknown error occured while capturing a video/photo."
}

View File

@@ -54,6 +54,8 @@ extension CameraSession {
// Something went wrong, we have an error
if error.domain == "capture/aborted" {
onError(.capture(.aborted))
} else if error.code == -11807 {
onError(.capture(.insufficientStorage))
} else {
onError(.capture(.unknown(message: "An unknown recording error occured! \(error.code) \(error.description)")))
}

View File

@@ -84,7 +84,11 @@ class PhotoCaptureDelegate: NSObject, AVCapturePhotoCaptureDelegate {
delegatesReferences.removeAll(where: { $0 == self })
}
if let error = error as NSError? {
promise.reject(error: .capture(.unknown(message: error.description)), cause: error)
if error.code == -11807 {
promise.reject(error: .capture(.insufficientStorage), cause: error)
} else {
promise.reject(error: .capture(.unknown(message: error.description)), cause: error)
}
return
}
}