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 2d9db329
authored
2026-04-21 18:43:39 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化错误场景的处理
1 parent
552c2145
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
9 deletions
lib/data/repositories/message/upload_start_handler.dart
lib/exception/exceptions.dart
lib/data/repositories/message/upload_start_handler.dart
View file @
2d9db32
...
@@ -5,6 +5,7 @@ import 'package:appframe/bloc/web_cubit.dart';
...
@@ -5,6 +5,7 @@ import 'package:appframe/bloc/web_cubit.dart';
import
'package:appframe/config/env_config.dart'
;
import
'package:appframe/config/env_config.dart'
;
import
'package:appframe/config/constant.dart'
;
import
'package:appframe/config/constant.dart'
;
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/exception/exceptions.dart'
;
import
'package:appframe/services/api_service.dart'
;
import
'package:appframe/services/api_service.dart'
;
import
'package:appframe/services/dispatcher.dart'
;
import
'package:appframe/services/dispatcher.dart'
;
import
'package:appframe/utils/file_type_util.dart'
;
import
'package:appframe/utils/file_type_util.dart'
;
...
@@ -49,22 +50,22 @@ class UploadStartHandler extends MessageHandler {
...
@@ -49,22 +50,22 @@ class UploadStartHandler extends MessageHandler {
Future
<
dynamic
>
handleMessage
(
params
)
async
{
Future
<
dynamic
>
handleMessage
(
params
)
async
{
try
{
try
{
if
(
params
is
!
Map
<
String
,
dynamic
>)
{
if
(
params
is
!
Map
<
String
,
dynamic
>)
{
throw
Exception
(
'参数错误'
);
throw
ParamErrorException
(
);
}
}
final
String
?
tempFilePath
=
params
[
'tempFilePath'
]
as
String
?;
final
String
?
tempFilePath
=
params
[
'tempFilePath'
]
as
String
?;
if
(
tempFilePath
==
null
||
tempFilePath
.
isEmpty
)
{
if
(
tempFilePath
==
null
||
tempFilePath
.
isEmpty
)
{
throw
Exception
(
'参数错误'
);
throw
ParamErrorException
(
);
}
}
final
String
?
busi
=
params
[
'busi'
]
as
String
?;
final
String
?
busi
=
params
[
'busi'
]
as
String
?;
if
(
busi
==
null
||
busi
.
isEmpty
)
{
if
(
busi
==
null
||
busi
.
isEmpty
)
{
throw
Exception
(
'参数错误'
);
throw
ParamErrorException
(
);
}
}
final
String
?
subBusi
=
params
[
'subBusi'
]
as
String
?;
final
String
?
subBusi
=
params
[
'subBusi'
]
as
String
?;
if
(
subBusi
==
null
||
subBusi
.
isEmpty
)
{
if
(
subBusi
==
null
||
subBusi
.
isEmpty
)
{
throw
Exception
(
'参数错误'
);
throw
ParamErrorException
(
);
}
}
// 开始处理前,先生成唯一 cmdUploadId
// 开始处理前,先生成唯一 cmdUploadId
...
@@ -81,12 +82,17 @@ class UploadStartHandler extends MessageHandler {
...
@@ -81,12 +82,17 @@ class UploadStartHandler extends MessageHandler {
// 返回 null,让 MessageDispatcher 不处理返回指令
// 返回 null,让 MessageDispatcher 不处理返回指令
return
null
;
return
null
;
}
on
ParamErrorException
{
debugPrint
(
'====================>上传失败:参数错误'
);
throw
Exception
(
'参数错误'
);
}
on
ChunkUploadFailedException
{
debugPrint
(
'====================>上传失败:网络错误'
);
// 确保发送了 uploadEnd 指令
_webCubit
?.
sendUploadEnd
(
_cmdUnique
,
_cmdUploadId
,
''
,
errMsg:
'网络错误,上传失败'
);
}
catch
(
e
)
{
}
catch
(
e
)
{
debugPrint
(
'====================>上传失败:
$e
'
);
debugPrint
(
'====================>上传失败:
$e
'
);
// 确保发送了 uploadEnd 指令
// 确保发送了 uploadEnd 指令
if
(
e
is
Exception
&&
e
.
toString
()
!=
Exception
(
'参数错误'
).
toString
())
{
_webCubit
?.
sendUploadEnd
(
_cmdUnique
,
_cmdUploadId
,
''
,
errMsg:
e
.
toString
());
_webCubit
?.
sendUploadEnd
(
_cmdUnique
,
_cmdUploadId
,
''
,
errMsg:
e
.
toString
());
}
}
finally
{
}
finally
{
_unfollowCubit
();
_unfollowCubit
();
}
}
...
@@ -367,12 +373,14 @@ class UploadStartHandler extends MessageHandler {
...
@@ -367,12 +373,14 @@ class UploadStartHandler extends MessageHandler {
return
{
'idx'
:
chunkIndex
+
1
,
'etag'
:
etags
[
0
]};
return
{
'idx'
:
chunkIndex
+
1
,
'etag'
:
etags
[
0
]};
}
else
{
}
else
{
throw
Exception
(
'Chunk
$chunkIndex
upload failed:
${resp.statusCode}
'
);
// throw Exception('Chunk $chunkIndex upload failed: ${resp.statusCode}');
throw
Exception
(
'Chunk upload failed'
);
}
}
}
catch
(
e
)
{
}
catch
(
e
)
{
debugPrint
(
'====================> 分片
$chunkIndex
第
${attempt + 1}
次, 上传失败:
${e.toString()}
'
);
debugPrint
(
'====================> 分片
$chunkIndex
第
${attempt + 1}
次, 上传失败:
${e.toString()}
'
);
if
(
attempt
==
maxRetries
)
{
if
(
attempt
==
maxRetries
)
{
throw
Exception
(
'Chunk
$chunkIndex
upload failed after
$maxRetries
attempts:
$e
'
);
// throw Exception('Chunk $chunkIndex upload failed after $maxRetries attempts: $e');
throw
Exception
(
'Chunk upload failed'
);
}
}
// 等待后重试
// 等待后重试
await
Future
.
delayed
(
Duration
(
seconds:
2
*
(
attempt
+
1
)));
await
Future
.
delayed
(
Duration
(
seconds:
2
*
(
attempt
+
1
)));
...
@@ -431,7 +439,8 @@ class UploadStartHandler extends MessageHandler {
...
@@ -431,7 +439,8 @@ class UploadStartHandler extends MessageHandler {
return
response
;
return
response
;
}
catch
(
e
)
{
}
catch
(
e
)
{
throw
Exception
(
'Chunk upload failed:
$e
'
);
// throw Exception('Chunk upload failed: $e');
throw
Exception
(
'Chunk upload failed'
);
}
}
}
}
...
...
lib/exception/exceptions.dart
0 → 100644
View file @
2d9db32
class
ParamErrorException
implements
Exception
{
final
String
message
;
ParamErrorException
([
this
.
message
=
'参数错误'
]);
@override
String
toString
()
=>
'ParamErrorException:
$message
'
;
}
class
ChunkUploadFailedException
implements
Exception
{
final
String
message
;
ChunkUploadFailedException
([
this
.
message
=
'Chunk upload failed'
]);
@override
String
toString
()
=>
'ChunkUploadFailedException:
$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