refactor(api): 统一前端API调用使用apiFetch并优化错误处理

refactor: 替换直接fetch调用为apiFetch以统一处理错误和响应
fix(server): 改进QR码验证的错误消息和密码哈希处理
This commit is contained in:
sudomarcma
2025-06-26 11:45:14 +08:00
parent e563f17283
commit 5e3015ba4f
8 changed files with 184 additions and 198 deletions
+6 -1
View File
@@ -19,7 +19,12 @@ export async function apiFetch(endpoint, options = {}) {
})
if (!response.ok) {
throw new Error(`API call failed with status: ${response.status}`)
// Try to parse the error response body from the server
const errorData = await response.json()
throw new Error(errorData.message || `API call failed with status: ${response.status}`)
}
if (response.status === 204) {
return null
}
return response.json()