( error: unknown, fallback = 'Something went wrong', )
| 101 | * Prefers the first GraphQL error message, then the error's message, then a fallback. |
| 102 | */ |
| 103 | export const getGraphQLErrorMessage = ( |
| 104 | error: unknown, |
| 105 | fallback = 'Something went wrong', |
| 106 | ): string => { |
| 107 | if (!error || typeof error !== 'object') return fallback; |
| 108 | const err = error as { |
| 109 | message?: string; |
| 110 | graphQLErrors?: Array<{ message?: string }>; |
| 111 | networkError?: { message?: string }; |
| 112 | }; |
| 113 | if (Array.isArray(err.graphQLErrors) && err.graphQLErrors.length > 0) { |
| 114 | const first = err.graphQLErrors[0]; |
| 115 | if (first?.message && typeof first.message === 'string') { |
| 116 | return first.message; |
| 117 | } |
| 118 | } |
| 119 | if (err.message && typeof err.message === 'string') return err.message; |
| 120 | if (err.networkError?.message) return err.networkError.message; |
| 121 | return fallback; |
| 122 | }; |
no outgoing calls
no test coverage detected