mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-25 10:58:50 +01:00
Fix handling errors from other download instances
This commit is contained in:
parent
6365a41833
commit
bb5440a7d6
3 changed files with 33 additions and 4 deletions
|
@ -59,7 +59,9 @@ class DownloadEventCompleteChannelHandler(context: Context) :
|
||||||
_eventSink?.error(
|
_eventSink?.error(
|
||||||
"downloadError",
|
"downloadError",
|
||||||
"Download #$downloadId was not successful, status: $status, reason: $reason",
|
"Download #$downloadId was not successful, status: $status, reason: $reason",
|
||||||
null
|
mapOf(
|
||||||
|
"downloadId" to downloadId
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -68,7 +70,9 @@ class DownloadEventCompleteChannelHandler(context: Context) :
|
||||||
"ID #$downloadId not found, user canceled the job?"
|
"ID #$downloadId not found, user canceled the job?"
|
||||||
)
|
)
|
||||||
_eventSink?.error(
|
_eventSink?.error(
|
||||||
"userCanceled", "Download #$downloadId was canceled", null
|
"userCanceled", "Download #$downloadId was canceled", mapOf(
|
||||||
|
"downloadId" to downloadId
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,16 @@ class DownloadEvent {
|
||||||
.map((data) => DownloadCompleteEvent(
|
.map((data) => DownloadCompleteEvent(
|
||||||
data["downloadId"],
|
data["downloadId"],
|
||||||
data["uri"],
|
data["uri"],
|
||||||
));
|
))
|
||||||
|
.handleError(
|
||||||
|
(e, stackTrace) {
|
||||||
|
throw AndroidDownloadError(e.details["downloadId"], e, stackTrace);
|
||||||
|
},
|
||||||
|
test: (e) =>
|
||||||
|
e is PlatformException &&
|
||||||
|
e.details is Map &&
|
||||||
|
e.details["downloadId"] is int,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class DownloadCompleteEvent {
|
class DownloadCompleteEvent {
|
||||||
|
@ -49,3 +58,11 @@ class DownloadCompleteEvent {
|
||||||
final int downloadId;
|
final int downloadId;
|
||||||
final String uri;
|
final String uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AndroidDownloadError implements Exception {
|
||||||
|
const AndroidDownloadError(this.downloadId, this.error, this.stackTrace);
|
||||||
|
|
||||||
|
final int downloadId;
|
||||||
|
final dynamic error;
|
||||||
|
final StackTrace stackTrace;
|
||||||
|
}
|
||||||
|
|
|
@ -62,7 +62,15 @@ class FileDownloader extends itf.FileDownloader {
|
||||||
subscription = DownloadEvent.listenDownloadComplete()
|
subscription = DownloadEvent.listenDownloadComplete()
|
||||||
..onData(onDownloadComplete)
|
..onData(onDownloadComplete)
|
||||||
..onError((e, stackTrace) {
|
..onError((e, stackTrace) {
|
||||||
completer.completeError(e, stackTrace);
|
if (e is AndroidDownloadError) {
|
||||||
|
if (e.downloadId != id) {
|
||||||
|
// not us, ignore
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
completer.completeError(e.error, e.stackTrace);
|
||||||
|
} else {
|
||||||
|
completer.completeError(e, stackTrace);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
await completer.future;
|
await completer.future;
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Reference in a new issue