mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-25 02:48:54 +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(
|
||||
"downloadError",
|
||||
"Download #$downloadId was not successful, status: $status, reason: $reason",
|
||||
null
|
||||
mapOf(
|
||||
"downloadId" to downloadId
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
|
@ -68,7 +70,9 @@ class DownloadEventCompleteChannelHandler(context: Context) :
|
|||
"ID #$downloadId not found, user canceled the job?"
|
||||
)
|
||||
_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(
|
||||
data["downloadId"],
|
||||
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 {
|
||||
|
@ -49,3 +58,11 @@ class DownloadCompleteEvent {
|
|||
final int downloadId;
|
||||
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()
|
||||
..onData(onDownloadComplete)
|
||||
..onError((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;
|
||||
} finally {
|
||||
|
|
Loading…
Reference in a new issue