refactor(api): 统一前端API调用使用apiFetch并优化错误处理
refactor: 替换直接fetch调用为apiFetch以统一处理错误和响应 fix(server): 改进QR码验证的错误消息和密码哈希处理
This commit is contained in:
+6
-1
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user