( error: Error | undefined | null )
| 2 | import { AxiosError } from "axios"; |
| 3 | |
| 4 | export function formatError( |
| 5 | error: Error | undefined | null |
| 6 | ): string | undefined { |
| 7 | if (error === undefined || error === null) { |
| 8 | return undefined; |
| 9 | } |
| 10 | if ((error as ApolloError).graphQLErrors) { |
| 11 | // show the first error |
| 12 | /**@todo: return multiple errors */ |
| 13 | const [gqlError] = (error as ApolloError).graphQLErrors; |
| 14 | if (gqlError && gqlError.message) { |
| 15 | return gqlError.message; |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | if (error instanceof AxiosError) { |
| 20 | return (error as AxiosError).message; |
| 21 | } |
| 22 | return String(error); |
| 23 | } |
no outgoing calls
no test coverage detected