TF-2769 Catch upload attachment error to modify exception

This commit is contained in:
DatDang
2024-04-10 17:29:32 +07:00
committed by Dat H. Pham
parent f2a20970aa
commit 7bc466bea3
@@ -81,6 +81,7 @@ class FileUploader {
UploadFileArguments argsUpload, UploadFileArguments argsUpload,
worker.TypeSendPort sendPort worker.TypeSendPort sendPort
) async { ) async {
try {
final rootIsolateToken = argsUpload.isolateToken; final rootIsolateToken = argsUpload.isolateToken;
BackgroundIsolateBinaryMessenger.ensureInitialized(rootIsolateToken); BackgroundIsolateBinaryMessenger.ensureInitialized(rootIsolateToken);
await HiveCacheConfig.instance.setUp(); await HiveCacheConfig.instance.setUp();
@@ -103,7 +104,7 @@ class FileUploader {
), ),
data: File(argsUpload.mobileFileUpload.filePath).openRead(), data: File(argsUpload.mobileFileUpload.filePath).openRead(),
onSendProgress: (count, total) { onSendProgress: (count, total) {
log('FileUploader::_handleUploadAttachmentAction():onSendProgress: FILE[${argsUpload.uploadId.id}] : { PROGRESS = $count | TOTAL = $total}'); log('FileUploader::_handleUploadAttachmentAction():onSendProgress: [${argsUpload.uploadId.id}] = $count');
sendPort.send( sendPort.send(
UploadingAttachmentUploadState( UploadingAttachmentUploadState(
argsUpload.uploadId, argsUpload.uploadId,
@@ -118,6 +119,16 @@ class FileUploader {
resultJson: resultJson, resultJson: resultJson,
fileName: argsUpload.mobileFileUpload.fileName fileName: argsUpload.mobileFileUpload.fileName
); );
} on DioError catch (exception) {
logError('FileUploader::_handleUploadAttachmentAction():DioError: $exception');
throw exception.copyWith(
requestOptions: exception.requestOptions.copyWith(data: ''));
} catch (exception) {
logError('FileUploader::_handleUploadAttachmentAction():OtherException: $exception');
rethrow;
}
} }
Future<Attachment?> _handleUploadAttachmentActionOnWeb( Future<Attachment?> _handleUploadAttachmentActionOnWeb(