Coves frontend - a photon fork
1import { t } from './i18n'
2
3// eslint-disable-next-line
4export function errorMessage(error: any, instance?: string): string {
5 try {
6 if (typeof error == 'string') {
7 try {
8 error = JSON.parse(error)
9 } catch {
10 /* try without catch would be cool imo */
11 }
12 }
13
14 if (error?.body?.message) {
15 error = JSON.parse(error?.body?.message)
16
17 if (typeof error?.message == 'string') {
18 // probably piefed weird error format
19 error = error.message
20 }
21 }
22 if (error?.message) {
23 error = error?.message
24 }
25 if (error?.error && typeof error?.error === 'string') {
26 error = error.error
27 }
28 if (!error) throw error
29
30 return t.get(`error.${error}`)
31 } catch {
32 return error as any
33 }
34}