fix: admin/login: complaints about wrong credentials on timeout
Massimo Melina committed
Jul 26, 2022 at 15:05 UTC
e47019fcc65130526ac4f97b1308f04915e10fc5
3 files changed
+6
-4
admin/src/LoginRequired.ts
+4
-2
@@ -47,8 +47,10 @@ function LoginForm() {
47
48
async function login(username: string, password: string) {
49
const res = await srpSequence(username, password, apiCall).catch(err => {
50
- throw err === 'trust' ? "Login aborted: server identity cannot be trusted"
51
- : "Wrong username or password"
50
+ throw err?.code === 401 ? "Wrong username or password"
51
+ : err === 'trust' ? "Login aborted: server identity cannot be trusted"
52
+ : err?.name === 'AbortError' ? "Server didn't respond"
53
+ : (err?.message || "Unknown error")
54
})
55
if (!res.adminUrl)
56
throw "This account has no Admin access"
admin/src/api.ts
+1
-1
@@ -32,7 +32,7 @@ export function apiCall(cmd: string, params?: Dict, { timeout=undefined }={}) :
32
33
const controller = new AbortController()
34
if (timeout !== false)
35
- setTimeout(() => controller.abort(), (timeoutByApi[cmd] ?? timeout ?? 10)*1000)
35
+ setTimeout(() => controller.abort('timeout'), 1000*(timeoutByApi[cmd] ?? timeout ?? 10))
36
return fetch(PREFIX+cmd, {
37
method: 'POST',
38
headers: { 'content-type': 'application/json' },
frontend/src/api.ts
+1
-1
@@ -19,7 +19,7 @@ export function apiCall(cmd: string, params?: Dict, options: ApiCallOptions={})
19
stop?.()
20
if (res.ok)
21
return res.json()
22
- const msg = 'Failed API ' + cmd
22
+ const msg = `Failed API ${cmd}: ${res.statusText}`
23
console.warn(msg + (params ? ' ' + JSON.stringify(params) : ''))
24
throw new ApiError(res.status, msg)
25
}, err => {