( error: unknown, fallbackError = 'Request failed', )
| 23 | }>; |
| 24 | |
| 25 | export const getBetterAuthErrorMessage = ( |
| 26 | error: unknown, |
| 27 | fallbackError = 'Request failed', |
| 28 | ): string => { |
| 29 | if (typeof error === 'string' && error) { |
| 30 | return error; |
| 31 | } |
| 32 | |
| 33 | if (error && typeof error === 'object') { |
| 34 | if ('message' in error && typeof error.message === 'string') { |
| 35 | return error.message; |
| 36 | } |
| 37 | |
| 38 | if ('error' in error && typeof error.error === 'string') { |
| 39 | return error.error; |
| 40 | } |
| 41 | |
| 42 | if ('code' in error && typeof error.code === 'string') { |
| 43 | return error.code; |
| 44 | } |
| 45 | |
| 46 | try { |
| 47 | return JSON.stringify(error); |
| 48 | } catch { |
| 49 | return fallbackError; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | return fallbackError; |
| 54 | }; |
| 55 | |
| 56 | const betterAuthPost = async <T = Record<string, unknown>>( |
| 57 | path: string, |
no outgoing calls
no test coverage detected