Skip to content

Commit

Permalink
fix(backup): patch-package react-native-background-upload to return
Browse files Browse the repository at this point in the history
server answer

This will allow to do work depending on the server answer, like file
conflict or quota exceeded.

Upstream PR : Vydia/react-native-background-upload#337
  • Loading branch information
zatteo committed Jul 26, 2023
1 parent 9537817 commit 4f0d74e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
36 changes: 36 additions & 0 deletions patches/react-native-background-upload+6.6.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
diff --git a/node_modules/react-native-background-upload/android/src/main/java/com/vydia/RNUploader/GlobalRequestObserverDelegate.kt b/node_modules/react-native-background-upload/android/src/main/java/com/vydia/RNUploader/GlobalRequestObserverDelegate.kt
index c89d495..5da9d14 100644
--- a/node_modules/react-native-background-upload/android/src/main/java/com/vydia/RNUploader/GlobalRequestObserverDelegate.kt
+++ b/node_modules/react-native-background-upload/android/src/main/java/com/vydia/RNUploader/GlobalRequestObserverDelegate.kt
@@ -9,6 +9,7 @@ import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEm
import net.gotev.uploadservice.data.UploadInfo
import net.gotev.uploadservice.network.ServerResponse
import net.gotev.uploadservice.observer.request.RequestObserverDelegate
+import net.gotev.uploadservice.exceptions.UploadError

class GlobalRequestObserverDelegate(reactContext: ReactApplicationContext) : RequestObserverDelegate {
private val TAG = "UploadReceiver"
@@ -28,6 +29,10 @@ class GlobalRequestObserverDelegate(reactContext: ReactApplicationContext) : Req
// Make sure we do not try to call getMessage() on a null object
if (exception != null) {
params.putString("error", exception.message)
+ if (exception is UploadError) {
+ params.putInt("responseCode", exception.serverResponse.code)
+ params.putString("responseBody", String(exception.serverResponse.body, Charsets.US_ASCII))
+ }
} else {
params.putString("error", "Unknown exception")
}
diff --git a/node_modules/react-native-background-upload/index.d.ts b/node_modules/react-native-background-upload/index.d.ts
index 8b2a07c..80cff93 100644
--- a/node_modules/react-native-background-upload/index.d.ts
+++ b/node_modules/react-native-background-upload/index.d.ts
@@ -11,6 +11,8 @@ declare module "react-native-background-upload" {

export interface ErrorData extends EventData {
error: string
+ responseCode: number
+ responseBody: string
}

export interface CompletedData extends EventData {
14 changes: 4 additions & 10 deletions src/app/domain/backup/services/uploadMedia.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import RNBackgroundUpload, {
import { getMimeType } from '/app/domain/backup/services/getMedias'
import { Media, UploadMediaResult } from '/app/domain/backup/models/Media'

import CozyClient, { IOCozyFile } from 'cozy-client'
import CozyClient, { StackErrors, IOCozyFile } from 'cozy-client'

let currentUploadId: string | undefined

Expand Down Expand Up @@ -50,16 +50,10 @@ export const uploadMedia = async (
setCurrentUploadId(uploadId)

RNBackgroundUpload.addListener('error', uploadId, error => {
// RNBackgroundUpload does not return status code and response body...
const { errors } = JSON.parse(error.responseBody) as StackErrors
reject({
statusCode: -1,
errors: [
{
status: -1,
title: error.error,
detail: error.error
}
]
statusCode: error.responseCode,
errors
})
})
RNBackgroundUpload.addListener('cancelled', uploadId, data => {
Expand Down

0 comments on commit 4f0d74e

Please sign in to comment.