Skip to content

Commit

Permalink
improve dio error log for attachment download/upload (#1285)
Browse files Browse the repository at this point in the history
* improve attachment download/upload dio error log

* improve upload/download stream error handle log
  • Loading branch information
boyan01 authored Jul 15, 2023
1 parent d368df6 commit 6a96496
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/utils/attachment/attachment_download_job.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ Future<void> _download(_AttachmentDownloadJobOption options) async {
if (options.keys != null && options.digest != null) {
_stream = _stream.decrypt(options.keys!, options.digest!, total);
}
return _stream.map((event) {
return _stream.handleError((error, stacktrace) {
e('download error: $error, stack: $stacktrace');
throw Exception(error);
}).map((event) {
received += event.length;
options.sendPort.send((received, total));
return event;
Expand All @@ -118,7 +121,10 @@ Future<void> _download(_AttachmentDownloadJobOption options) async {
if (response.statusCode != 200) throw Error();
options.sendPort.send(_completeMessage);
} catch (error, s) {
e('download error: $e, stack: $s');
e('download error: $error, stack: $s');
if (error is DioError) {
e('original stacktrace: ${error.stackTrace}');
}
options.sendPort.send(_killMessage);
}
}
Expand Down
8 changes: 7 additions & 1 deletion lib/utils/attachment/attachment_upload_job.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ Future<void> _upload(_AttachmentUploadJobOption options) async {
_dio.applyProxy(options.proxy);
final response = await _dio.putUri(
Uri.parse(options.url),
data: uploadStream,
data: uploadStream.handleError((error, stacktrace) {
e('uploadStream error: $error $stacktrace');
throw Exception(error);
}),
options: Options(
headers: {
..._uploadHeaders,
Expand All @@ -137,6 +140,9 @@ Future<void> _upload(_AttachmentUploadJobOption options) async {
options.sendPort.send(digest);
} catch (error, stacktrace) {
e('failed to upload attachment $error, $stacktrace');
if (error is DioError) {
e('original stacktrace: ${error.stackTrace}');
}
options.sendPort.send(_killMessage);
}
}

0 comments on commit 6a96496

Please sign in to comment.