-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathapi.ts
30 lines (26 loc) · 852 Bytes
/
api.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*--------------------------------------------------------------------------
* Copyright (c) 2019-2021, Postgres.ai, Nikolay Samokhvalov nik@postgres.ai
* All Rights Reserved. Proprietary and confidential.
* Unauthorized copying of this file, via any medium is strictly prohibited
*--------------------------------------------------------------------------
*/
export const getTextFromUnknownApiError = async (error: Response) => {
const log = (text: string) => console.error('Unknown API error', text)
try {
const result = await error.json()
log(result)
return JSON.stringify(result)
} catch (e) {
// not a json
}
try {
const result = await error.text()
log(result)
return result
} catch (e) {
// not a text
}
const result = `${error.status} ${error.statusText}`
log(result)
return result
}