fix: 修复推荐码验证 API 错误处理
后端修复: - getUserByReferralCode() 在推荐码不存在时抛出异常 - 之前返回 null,导致前端无法正确判断错误 前端修复: - 增强 verifyReferralCode() 的响应检查 - 检查 response.data 和 data 字段是否为 null - 添加详细的 debug 日志输出 - null 响应视为推荐码无效并抛出异常 问题原因: - 后端返回 null 时,前端解析 response.data.data 会得到 null - 前端没有检查 null 情况,导致显示 "status: null" 错误 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
08ec49322d
commit
14d4107a10
|
|
@ -779,7 +779,9 @@ export class UserApplicationService {
|
|||
const account = await this.userRepository.findByReferralCode(
|
||||
ReferralCode.create(query.referralCode),
|
||||
);
|
||||
if (!account) return null;
|
||||
if (!account) {
|
||||
throw new ApplicationError('推荐码不存在或无效');
|
||||
}
|
||||
|
||||
return {
|
||||
userId: account.userId.toString(),
|
||||
|
|
|
|||
|
|
@ -1422,13 +1422,27 @@ class AccountService {
|
|||
final response = await _apiClient.get(
|
||||
'/user/by-referral-code/$referralCode',
|
||||
);
|
||||
debugPrint('$_tag verifyReferralCode() - 推荐码有效');
|
||||
|
||||
final responseData = response.data as Map<String, dynamic>;
|
||||
return responseData['data'] as Map<String, dynamic>? ?? responseData;
|
||||
debugPrint('$_tag verifyReferralCode() - API 响应: ${response.data}');
|
||||
|
||||
// 检查响应数据
|
||||
final responseData = response.data as Map<String, dynamic>?;
|
||||
if (responseData == null) {
|
||||
debugPrint('$_tag verifyReferralCode() - 响应数据为 null');
|
||||
throw ApiException('推荐码不存在或无效');
|
||||
}
|
||||
|
||||
final data = responseData['data'];
|
||||
if (data == null) {
|
||||
debugPrint('$_tag verifyReferralCode() - data 字段为 null');
|
||||
throw ApiException('推荐码不存在或无效');
|
||||
}
|
||||
|
||||
debugPrint('$_tag verifyReferralCode() - 推荐码有效');
|
||||
return data as Map<String, dynamic>;
|
||||
} on ApiException catch (e) {
|
||||
debugPrint('$_tag verifyReferralCode() - 推荐码无效: $e');
|
||||
throw ApiException('推荐码不存在或无效');
|
||||
debugPrint('$_tag verifyReferralCode() - API 异常: $e');
|
||||
rethrow;
|
||||
} catch (e, stackTrace) {
|
||||
debugPrint('$_tag verifyReferralCode() - 未知异常: $e');
|
||||
debugPrint('$_tag verifyReferralCode() - 堆栈: $stackTrace');
|
||||
|
|
|
|||
Loading…
Reference in New Issue