Skip to content

Commit

Permalink
fix(nextcloud): Emit errors in WebDAV getStream
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Feb 11, 2024
1 parent 77e9a9b commit 4261997
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
46 changes: 26 additions & 20 deletions packages/nextcloud/lib/src/webdav/client.dart
Expand Up @@ -236,26 +236,32 @@ class WebDavClient {
_send(
'GET',
_constructUri(path),
).then((response) async {
final contentLength = response.contentLength;
if (contentLength == null || contentLength <= 0) {
onProgress?.call(1);
} else {
final completer = Completer<void>();
var downloaded = 0;

response.stream.listen((chunk) async {
controller.add(chunk);
downloaded += chunk.length;
onProgress?.call(downloaded / contentLength);
if (downloaded >= contentLength) {
completer.complete();
}
});
await completer.future;
}
await controller.close();
}),
).then(
(response) async {
final contentLength = response.contentLength;
if (contentLength == null || contentLength <= 0) {
onProgress?.call(1);
} else {
final completer = Completer<void>();
var downloaded = 0;

response.stream.listen((chunk) async {
controller.add(chunk);
downloaded += chunk.length;
onProgress?.call(downloaded / contentLength);
if (downloaded >= contentLength) {
completer.complete();
}
});
await completer.future;
}
await controller.close();
},
// ignore: avoid_types_on_closure_parameters
onError: (Object error) {
controller.addError(error);
},
),
);

return controller.stream;
Expand Down
@@ -0,0 +1,3 @@
GET http://localhost/remote\.php/webdav/404\.txt
authorization: Bearer mock
content-type: application/xml
7 changes: 7 additions & 0 deletions packages/nextcloud/test/webdav_test.dart
Expand Up @@ -469,6 +469,13 @@ void main() {
destinationDir.deleteSync(recursive: true);
});

test('getStream error handling', () async {
expect(
client.webdav.getStream(PathUri.parse('404.txt')),
emitsError(predicate<DynamiteStatusCodeException>((e) => e.statusCode == 404)),
);
});

group('litmus', () {
group('basic', () {
test('options', () async {
Expand Down

0 comments on commit 4261997

Please sign in to comment.