(error: unknown)
| 108 | } |
| 109 | |
| 110 | export function printError(error: unknown) { |
| 111 | // Coerce Strings to Error instances |
| 112 | if (typeof error === 'string') { |
| 113 | error = new Error(error); |
| 114 | } |
| 115 | |
| 116 | const apiError = error as APIError; |
| 117 | const { message, stack, status, code, sizeLimit } = apiError; |
| 118 | |
| 119 | output.debug(`handling error: ${stack}`); |
| 120 | |
| 121 | if (message === 'User force closed the prompt with 0 null') { |
| 122 | return; |
| 123 | } |
| 124 | |
| 125 | if (status === 403) { |
| 126 | output.error( |
| 127 | message || |
| 128 | `Authentication error. Run ${getCommandName('login')} to log-in again.` |
| 129 | ); |
| 130 | } else if (status === 429) { |
| 131 | // Rate limited: display the message from the server-side, |
| 132 | // which contains more details |
| 133 | output.error(message); |
| 134 | } else if (code === 'size_limit_exceeded') { |
| 135 | output.error(`File size limit exceeded (${bytes(sizeLimit)})`); |
| 136 | } else if (message) { |
| 137 | output.prettyError(apiError); |
| 138 | } else if (status === 500) { |
| 139 | output.error('Unexpected server error. Please retry.'); |
| 140 | } else if (code === 'USER_ABORT') { |
| 141 | output.log('Canceled'); |
| 142 | } else { |
| 143 | output.error(`Unexpected error. Please try again later. (${message})`); |
| 144 | } |
| 145 | } |
no test coverage detected