修复注册重复账户时,提示错误信息的bug
This commit is contained in:
@@ -1,100 +1,55 @@
|
|||||||
index.uvue:1 GET http://localhost:5173/pages/mall/admin/userCenter/index.uvue?t=1773217839799&import&vue&type=script&setup=true&lang.uts net::ERR_ABORTED 500 (Internal Server Error)
|
ak-req.uts:144
|
||||||
main.uts:16 [Vue warn]: Unhandled error during execution of async component loader
|
POST http://119.146.131.237:9126/auth/v1/signup 500 (Internal Server Error)
|
||||||
at <AsyncComponentWrapper>
|
register.uvue:221 📝 注册返回结果:
|
||||||
at <PageBody>
|
UTSJSONObject2 {code: '23505', message: 'duplicate key value violates unique constraint "ak_users_email_key"', detail: 'Key (email)=(admin@163.com) already exists.', _resolveKeyPath: ƒ, _getValue: ƒ, …}
|
||||||
at <Page>
|
code
|
||||||
at <Anonymous>
|
:
|
||||||
at <KeepAlive>
|
"23505"
|
||||||
at <RouterView>
|
detail
|
||||||
at <Layout>
|
:
|
||||||
at <App>
|
"Key (email)=(admin@163.com) already exists."
|
||||||
warnHandler @ uni-h5.es.js:19975
|
message
|
||||||
callWithErrorHandling @ vue.runtime.esm.js:1381
|
:
|
||||||
warn$1 @ vue.runtime.esm.js:1207
|
"duplicate key value violates unique constraint \"ak_users_email_key\""
|
||||||
logError @ vue.runtime.esm.js:1438
|
forEach
|
||||||
errorHandler @ uni-h5.es.js:19600
|
:
|
||||||
callWithErrorHandling @ vue.runtime.esm.js:1381
|
ƒ forEach(callback)
|
||||||
handleError @ vue.runtime.esm.js:1421
|
get
|
||||||
onError @ vue.runtime.esm.js:3724
|
:
|
||||||
(anonymous) @ vue.runtime.esm.js:3767
|
ƒ get(key)
|
||||||
Promise.catch
|
getAny
|
||||||
setup @ vue.runtime.esm.js:3766
|
:
|
||||||
callWithErrorHandling @ vue.runtime.esm.js:1381
|
ƒ getAny(key, defaultValue)
|
||||||
setupStatefulComponent @ vue.runtime.esm.js:8985
|
getArray
|
||||||
setupComponent @ vue.runtime.esm.js:8946
|
:
|
||||||
mountComponent @ vue.runtime.esm.js:7262
|
ƒ getArray(key, defaultValue)
|
||||||
processComponent @ vue.runtime.esm.js:7228
|
getBoolean
|
||||||
patch @ vue.runtime.esm.js:6694
|
:
|
||||||
mountChildren @ vue.runtime.esm.js:6942
|
ƒ getBoolean(key, defaultValue)
|
||||||
processFragment @ vue.runtime.esm.js:7158
|
getJSON
|
||||||
patch @ vue.runtime.esm.js:6668
|
:
|
||||||
mountChildren @ vue.runtime.esm.js:6942
|
ƒ getJSON(key, defaultValue)
|
||||||
processFragment @ vue.runtime.esm.js:7158
|
getNumber
|
||||||
patch @ vue.runtime.esm.js:6668
|
:
|
||||||
mountChildren @ vue.runtime.esm.js:6942
|
ƒ getNumber(key, defaultValue)
|
||||||
mountElement @ vue.runtime.esm.js:6849
|
getString
|
||||||
processElement @ vue.runtime.esm.js:6814
|
:
|
||||||
patch @ vue.runtime.esm.js:6682
|
ƒ getString(key, defaultValue)
|
||||||
mountChildren @ vue.runtime.esm.js:6942
|
set
|
||||||
mountElement @ vue.runtime.esm.js:6849
|
:
|
||||||
processElement @ vue.runtime.esm.js:6814
|
ƒ set(key, value)
|
||||||
patch @ vue.runtime.esm.js:6682
|
toJSON
|
||||||
mountChildren @ vue.runtime.esm.js:6942
|
:
|
||||||
processFragment @ vue.runtime.esm.js:7158
|
undefined
|
||||||
patch @ vue.runtime.esm.js:6668
|
toMap
|
||||||
componentUpdateFn @ vue.runtime.esm.js:7372
|
:
|
||||||
run @ vue.runtime.esm.js:153
|
ƒ toMap()
|
||||||
instance.update @ vue.runtime.esm.js:7497
|
_getValue
|
||||||
setupRenderEffect @ vue.runtime.esm.js:7507
|
:
|
||||||
mountComponent @ vue.runtime.esm.js:7274
|
ƒ _getValue(keyPath, defaultValue)
|
||||||
processComponent @ vue.runtime.esm.js:7228
|
_resolveKeyPath
|
||||||
patch @ vue.runtime.esm.js:6694
|
:
|
||||||
mountChildren @ vue.runtime.esm.js:6942
|
ƒ _resolveKeyPath(keyPath)
|
||||||
mountElement @ vue.runtime.esm.js:6849
|
[[Prototype]]
|
||||||
processElement @ vue.runtime.esm.js:6814
|
:
|
||||||
patch @ vue.runtime.esm.js:6682
|
Object
|
||||||
componentUpdateFn @ vue.runtime.esm.js:7372
|
|
||||||
run @ vue.runtime.esm.js:153
|
|
||||||
instance.update @ vue.runtime.esm.js:7497
|
|
||||||
setupRenderEffect @ vue.runtime.esm.js:7507
|
|
||||||
mountComponent @ vue.runtime.esm.js:7274
|
|
||||||
processComponent @ vue.runtime.esm.js:7228
|
|
||||||
patch @ vue.runtime.esm.js:6694
|
|
||||||
componentUpdateFn @ vue.runtime.esm.js:7372
|
|
||||||
run @ vue.runtime.esm.js:153
|
|
||||||
instance.update @ vue.runtime.esm.js:7497
|
|
||||||
setupRenderEffect @ vue.runtime.esm.js:7507
|
|
||||||
mountComponent @ vue.runtime.esm.js:7274
|
|
||||||
processComponent @ vue.runtime.esm.js:7228
|
|
||||||
patch @ vue.runtime.esm.js:6694
|
|
||||||
componentUpdateFn @ vue.runtime.esm.js:7453
|
|
||||||
run @ vue.runtime.esm.js:153
|
|
||||||
instance.update @ vue.runtime.esm.js:7497
|
|
||||||
updateComponent @ vue.runtime.esm.js:7305
|
|
||||||
processComponent @ vue.runtime.esm.js:7239
|
|
||||||
patch @ vue.runtime.esm.js:6694
|
|
||||||
componentUpdateFn @ vue.runtime.esm.js:7453
|
|
||||||
run @ vue.runtime.esm.js:153
|
|
||||||
instance.update @ vue.runtime.esm.js:7497
|
|
||||||
callWithErrorHandling @ vue.runtime.esm.js:1381
|
|
||||||
flushJobs @ vue.runtime.esm.js:1585
|
|
||||||
Promise.then
|
|
||||||
queueFlush @ vue.runtime.esm.js:1494
|
|
||||||
queueJob @ vue.runtime.esm.js:1488
|
|
||||||
scheduler @ vue.runtime.esm.js:3179
|
|
||||||
resetScheduling @ vue.runtime.esm.js:236
|
|
||||||
triggerEffects @ vue.runtime.esm.js:280
|
|
||||||
triggerRefValue @ vue.runtime.esm.js:1033
|
|
||||||
set value @ vue.runtime.esm.js:1078
|
|
||||||
finalizeNavigation @ vue-router.mjs?v=ed041164:2474
|
|
||||||
(anonymous) @ vue-router.mjs?v=ed041164:2384
|
|
||||||
Promise.then
|
|
||||||
pushWithRedirect @ vue-router.mjs?v=ed041164:2352
|
|
||||||
push @ vue-router.mjs?v=ed041164:2278
|
|
||||||
install @ vue-router.mjs?v=ed041164:2631
|
|
||||||
use @ vue.runtime.esm.js:5190
|
|
||||||
initRouter @ uni-h5.es.js:19886
|
|
||||||
install @ uni-h5.es.js:19955
|
|
||||||
use @ vue.runtime.esm.js:5190
|
|
||||||
(anonymous) @ main.uts:16
|
|
||||||
main.uts:16 TypeError: Failed to fetch dynamically imported module: http://localhost:5173/pages/mall/admin/homePage/index.uvue?t=1773218041262&import
|
|
||||||
@@ -69,8 +69,8 @@
|
|||||||
@input="(e: any) => password = e.detail.value"
|
@input="(e: any) => password = e.detail.value"
|
||||||
/>
|
/>
|
||||||
<view class="eye-btn" @click="isPasswordVisible = !isPasswordVisible">
|
<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>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -45,8 +45,8 @@
|
|||||||
class="input-field"
|
class="input-field"
|
||||||
/>
|
/>
|
||||||
<view class="eye-btn" @click="isPasswordVisible = !isPasswordVisible">
|
<view class="eye-btn" @click="isPasswordVisible = !isPasswordVisible">
|
||||||
<!-- 睁眼表示可见, 闭眼表示不可见 -->
|
<!-- 睁眼(猴子双手打开)表示可见, 闭眼(猴子捂眼)表示不可见 -->
|
||||||
<text class="eye-icon">{{ isPasswordVisible ? '👁️' : '🙈' }}</text>
|
<text class="eye-icon">{{ isPasswordVisible ? '🙉' : '🙈' }}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
class="input-field"
|
class="input-field"
|
||||||
/>
|
/>
|
||||||
<view class="eye-btn" @click="isConfirmPasswordVisible = !isConfirmPasswordVisible">
|
<view class="eye-btn" @click="isConfirmPasswordVisible = !isConfirmPasswordVisible">
|
||||||
<text class="eye-icon">{{ isConfirmPasswordVisible ? '👁️' : '🙈' }}</text>
|
<text class="eye-icon">{{ isConfirmPasswordVisible ? '🙉' : '🙈' }}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -227,8 +227,20 @@
|
|||||||
|
|
||||||
// 检查是否有错误
|
// 检查是否有错误
|
||||||
const errorCode = result?.getString('error_code') ?? ''
|
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
|
let user: UTSJSONObject | null = null
|
||||||
|
|
||||||
@@ -244,12 +256,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果返回错误且没有用户信息,说明注册失败
|
// 2. 如果没有返回能够标识用户的字段,应当直接按失败处理
|
||||||
if (user == null && code !== 0 && code !== 200) {
|
if (user == null) {
|
||||||
if (code === 500 && errorMsg.includes('confirmation email')) {
|
if ((codeNum === 500 || codeStr === '500') && errorMsg.includes('confirmation email')) {
|
||||||
throw new Error('注册失败:邮件服务配置错误')
|
throw new Error('注册失败:邮件服务配置错误')
|
||||||
} else {
|
} else {
|
||||||
throw new Error(errorMsg || '注册失败,请重试')
|
throw new Error(errorMsg || '该账户可能已经存在,或注册请重试')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user