fix: pass api error messages out to dialogs

Massimo Melina committed Mar 5, 2022 at 12:56 UTC 680acddb08bae04185b2555554fc6f01ea01c45f
1 file changed +2 -2
admin/src/api.ts
+2 -2
@@ -23,13 +23,13 @@ export function apiCall(cmd: string, params?: Dict) : Promise<any> {
23 method: 'POST',
24 headers: { 'content-type': 'application/json' },
25 body: params && JSON.stringify(params),
26 - }).then(res => {
26 + }).then(async res => {
27 if (res.ok)
28 return res.json().then(json => {
29 console.debug('API', cmd, params, '>>', json)
30 return json
31 })
32 - const msg = 'Failed API ' + cmd
32 + const msg = await res.text() || 'Failed API ' + cmd
33 console.warn(msg + (params ? ' ' + JSON.stringify(params) : ''))
34 if (res.status === 401)
35 state.loginRequired = true