修复注册重复账户时,提示错误信息的bug
This commit is contained in:
@@ -69,8 +69,8 @@
|
||||
@input="(e: any) => password = e.detail.value"
|
||||
/>
|
||||
<view class="eye-btn" @click="isPasswordVisible = !isPasswordVisible">
|
||||
<!-- 睁眼表示可见(type='text'), 闭眼表示不可见(type='password') -->
|
||||
<text class="eye-icon">{{ isPasswordVisible ? '👁️' : '🙈' }}</text>
|
||||
<!-- 睁眼(猴子双手打开)表示可见, 闭眼(猴子捂眼)表示不可见 -->
|
||||
<text class="eye-icon">{{ isPasswordVisible ? '🙉' : '🙈' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
@@ -45,8 +45,8 @@
|
||||
class="input-field"
|
||||
/>
|
||||
<view class="eye-btn" @click="isPasswordVisible = !isPasswordVisible">
|
||||
<!-- 睁眼表示可见, 闭眼表示不可见 -->
|
||||
<text class="eye-icon">{{ isPasswordVisible ? '👁️' : '🙈' }}</text>
|
||||
<!-- 睁眼(猴子双手打开)表示可见, 闭眼(猴子捂眼)表示不可见 -->
|
||||
<text class="eye-icon">{{ isPasswordVisible ? '🙉' : '🙈' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -63,7 +63,7 @@
|
||||
class="input-field"
|
||||
/>
|
||||
<view class="eye-btn" @click="isConfirmPasswordVisible = !isConfirmPasswordVisible">
|
||||
<text class="eye-icon">{{ isConfirmPasswordVisible ? '👁️' : '🙈' }}</text>
|
||||
<text class="eye-icon">{{ isConfirmPasswordVisible ? '🙉' : '🙈' }}</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -227,8 +227,20 @@
|
||||
|
||||
// 检查是否有错误
|
||||
const errorCode = result?.getString('error_code') ?? ''
|
||||
const errorMsg = result?.getString('msg') ?? ''
|
||||
const code = result?.getNumber('code') ?? 0
|
||||
// 兼容不同平台的报错字段
|
||||
const errorMsg = result?.getString('msg') ?? result?.getString('message') ?? ''
|
||||
const codeStr = result?.getString('code') ?? ''
|
||||
let codeNum = 0
|
||||
try {
|
||||
codeNum = result?.getNumber('code') ?? 0
|
||||
} catch(e) {
|
||||
// 忽略转换异常
|
||||
}
|
||||
|
||||
// 1. 明确判断是否为账户已存在 (PostgreSQL code 23505 或包含 duplicate/already exists)
|
||||
if (codeStr === '23505' || errorCode === 'user_already_exists' || errorMsg.includes('already exists') || errorMsg.includes('duplicate')) {
|
||||
throw new Error('该账户已经存在,请更换账户')
|
||||
}
|
||||
|
||||
let user: UTSJSONObject | null = null
|
||||
|
||||
@@ -244,12 +256,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 如果返回错误且没有用户信息,说明注册失败
|
||||
if (user == null && code !== 0 && code !== 200) {
|
||||
if (code === 500 && errorMsg.includes('confirmation email')) {
|
||||
// 2. 如果没有返回能够标识用户的字段,应当直接按失败处理
|
||||
if (user == null) {
|
||||
if ((codeNum === 500 || codeStr === '500') && errorMsg.includes('confirmation email')) {
|
||||
throw new Error('注册失败:邮件服务配置错误')
|
||||
} else {
|
||||
throw new Error(errorMsg || '注册失败,请重试')
|
||||
throw new Error(errorMsg || '该账户可能已经存在,或注册请重试')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user