f
This commit is contained in:
@@ -24,6 +24,7 @@ import (
|
||||
subordinate_repositories "tyapi-server/internal/domains/subordinate/repositories"
|
||||
user_repositories "tyapi-server/internal/domains/user/repositories"
|
||||
task_entities "tyapi-server/internal/infrastructure/task/entities"
|
||||
"tyapi-server/internal/infrastructure/external/shujubao"
|
||||
"tyapi-server/internal/infrastructure/task/interfaces"
|
||||
"tyapi-server/internal/shared/crypto"
|
||||
"tyapi-server/internal/shared/database"
|
||||
@@ -165,6 +166,11 @@ func (s *ApiApplicationServiceImpl) CallApi(ctx context.Context, cmd *commands.A
|
||||
|
||||
// 3. 同步调用外部API(核心业务)
|
||||
response, err := s.callExternalApi(ctx, cmd, validationResult)
|
||||
if errors.Is(err, ErrQueryEmptyBillable) {
|
||||
go s.asyncSaveApiCall(context.Background(), apiCall, validationResult, "")
|
||||
go s.asyncProcessDeduction(context.Background(), apiCall, validationResult)
|
||||
return transactionId, "", ErrQueryEmpty
|
||||
}
|
||||
if err != nil {
|
||||
// 异步记录失败状态
|
||||
go s.asyncRecordFailure(context.Background(), apiCall, err)
|
||||
@@ -399,6 +405,11 @@ func (s *ApiApplicationServiceImpl) callExternalApi(ctx context.Context, cmd *co
|
||||
callContext)
|
||||
|
||||
if err != nil {
|
||||
// 数据宝 10001/10006:查空但计费,由 CallApi 统一处理
|
||||
if errors.Is(err, shujubao.ErrQueryEmpty) {
|
||||
return "", ErrQueryEmptyBillable
|
||||
}
|
||||
|
||||
mappedErrorType := entities.ApiCallErrorSystem
|
||||
if errors.Is(err, processors.ErrDatasource) {
|
||||
mappedErrorType = entities.ApiCallErrorDatasource
|
||||
|
||||
@@ -5,6 +5,8 @@ import "errors"
|
||||
// API调用相关错误类型
|
||||
var (
|
||||
ErrQueryEmpty = errors.New("查询为空")
|
||||
// ErrQueryEmptyBillable 数据宝查空(10001/10006):对外返回查询为空,但仍正常扣费
|
||||
ErrQueryEmptyBillable = errors.New("查询为空")
|
||||
ErrQueryFailed = errors.New("查询失败")
|
||||
ErrSystem = errors.New("接口异常")
|
||||
ErrDecryptFail = errors.New("解密失败")
|
||||
|
||||
Reference in New Issue
Block a user