refactor: optimize error output in verifyToken
This commit is contained in:
@@ -30,20 +30,17 @@ export default class DevstarAPIHandler {
|
|||||||
// 处理非200响应状态码
|
// 处理非200响应状态码
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const text = await response.text(); // 先读取文本防止json解析失败
|
const text = await response.text(); // 先读取文本防止json解析失败
|
||||||
if (text === 'verify') {
|
throw new Error(`HTTP Error: ${response.status} - ${text}`);
|
||||||
console.error('Token错误')
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
throw new Error(`HTTP Error: ${response.status} - ${text}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
if (data.username == undefined || data.username == "") {
|
||||||
// 验证用户名匹配
|
throw new Error('Token对应用户不存在')
|
||||||
if (data.username !== username) {
|
} else {
|
||||||
console.error('Token与用户名不符');
|
// 验证用户名匹配
|
||||||
return false
|
if (data.username !== username) {
|
||||||
|
throw new Error('Token与用户名不符');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Reference in New Issue
Block a user