Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 647ceae6
authored
2026-04-23 10:13:07 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
继续优化错误场景的处理
1 parent
2d9db329
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
4 deletions
lib/data/repositories/message/upload_start_handler.dart
lib/exception/exceptions.dart
lib/data/repositories/message/upload_start_handler.dart
View file @
647ceae
...
...
@@ -85,6 +85,10 @@ class UploadStartHandler extends MessageHandler {
}
on
ParamErrorException
{
debugPrint
(
'====================>上传失败:参数错误'
);
throw
Exception
(
'参数错误'
);
}
on
ChunkSigException
{
debugPrint
(
'====================>上传失败:签名错误'
);
// 确保发送了 uploadEnd 指令
_webCubit
?.
sendUploadEnd
(
_cmdUnique
,
_cmdUploadId
,
''
,
errMsg:
'网络错误,签名失败'
);
}
on
ChunkUploadFailedException
{
debugPrint
(
'====================>上传失败:网络错误'
);
// 确保发送了 uploadEnd 指令
...
...
@@ -331,9 +335,13 @@ class UploadStartHandler extends MessageHandler {
/// 初始化,请求后端获取签名信息和上传任务ID
Future
<
Map
<
String
,
dynamic
>>
_init
(
ApiService
bxeApiService
,
String
objectKey
,
String
bucket
)
async
{
try
{
var
endpoint
=
'
$_signatureNewUrl
?objectKey=
$objectKey
&bucket=
$bucket
'
;
final
resp
=
await
bxeApiService
.
get
(
endpoint
);
return
resp
.
data
;
}
catch
(
e
)
{
throw
ChunkSigException
(
'初始化上传任务失败:
$e
'
);
}
}
/// 每次上传前,请求后端获取签名信息
...
...
@@ -344,9 +352,13 @@ class UploadStartHandler extends MessageHandler {
String
uploadId
,
int
partNum
,
)
async
{
try
{
var
endpoint
=
'
$_signatureNextUrl
?objectKey=
$objectKey
&bucket=
$bucket
&uploadId=
$uploadId
&partNum=
$partNum
'
;
final
resp
=
await
bxeApiService
.
get
(
endpoint
);
return
resp
.
data
;
}
catch
(
e
)
{
throw
ChunkSigException
(
'获取签名信息失败:
$e
'
);
}
}
/// 上传段(带进度回调)
...
...
@@ -374,13 +386,13 @@ class UploadStartHandler extends MessageHandler {
return
{
'idx'
:
chunkIndex
+
1
,
'etag'
:
etags
[
0
]};
}
else
{
// throw Exception('Chunk $chunkIndex upload failed: ${resp.statusCode}');
throw
Exception
(
'Chunk upload failed'
);
throw
ChunkUploadFailed
Exception
(
'Chunk upload failed'
);
}
}
catch
(
e
)
{
debugPrint
(
'====================> 分片
$chunkIndex
第
${attempt + 1}
次, 上传失败:
${e.toString()}
'
);
if
(
attempt
==
maxRetries
)
{
// throw Exception('Chunk $chunkIndex upload failed after $maxRetries attempts: $e');
throw
Exception
(
'Chunk upload failed'
);
throw
ChunkUploadFailed
Exception
(
'Chunk upload failed'
);
}
// 等待后重试
await
Future
.
delayed
(
Duration
(
seconds:
2
*
(
attempt
+
1
)));
...
...
@@ -440,7 +452,7 @@ class UploadStartHandler extends MessageHandler {
return
response
;
}
catch
(
e
)
{
// throw Exception('Chunk upload failed: $e');
throw
Exception
(
'Chunk upload failed'
);
throw
ChunkUploadFailed
Exception
(
'Chunk upload failed'
);
}
}
...
...
@@ -452,6 +464,7 @@ class UploadStartHandler extends MessageHandler {
String
uploadId
,
Map
<
int
,
String
>
tagsMap
,
)
async
{
try
{
final
parts
=
[];
for
(
int
i
=
1
;
i
<=
tagsMap
.
length
;
i
++)
{
parts
.
add
({
'partNumber'
:
i
,
'etag'
:
tagsMap
[
i
]});
...
...
@@ -465,10 +478,16 @@ class UploadStartHandler extends MessageHandler {
});
if
(
response
.
statusCode
!=
200
)
{
throw
Exception
(
'合并文件失败'
);
throw
ChunkSig
Exception
(
'合并文件失败'
);
}
return
response
.
data
[
"location"
];
}
catch
(
e
)
{
if
(
e
is
ChunkSigException
)
{
rethrow
;
}
throw
ChunkSigException
(
'合并文件失败:
$e
'
);
}
}
String
_getLoginPrefix
(
String
busi
,
String
subBusi
)
{
...
...
lib/exception/exceptions.dart
View file @
647ceae
...
...
@@ -7,6 +7,15 @@ class ParamErrorException implements Exception {
String
toString
()
=>
'ParamErrorException:
$message
'
;
}
class
ChunkSigException
implements
Exception
{
final
String
message
;
ChunkSigException
([
this
.
message
=
'签名失败'
]);
@override
String
toString
()
=>
'ChunkSigException:
$message
'
;
}
class
ChunkUploadFailedException
implements
Exception
{
final
String
message
;
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment