( status: number, data: unknown, context: string, )
| 452 | } |
| 453 | |
| 454 | function handleErrorStatus( |
| 455 | status: number, |
| 456 | data: unknown, |
| 457 | context: string, |
| 458 | ): void { |
| 459 | if (status === 200 || status === 204) { |
| 460 | return |
| 461 | } |
| 462 | const detail = extractErrorDetail(data) |
| 463 | const errorType = extractErrorTypeFromData(data) |
| 464 | switch (status) { |
| 465 | case 401: |
| 466 | throw new BridgeFatalError( |
| 467 | `${context}: Authentication failed (401)${detail ? `: ${detail}` : ''}. ${BRIDGE_LOGIN_INSTRUCTION}`, |
| 468 | 401, |
| 469 | errorType, |
| 470 | ) |
| 471 | case 403: |
| 472 | throw new BridgeFatalError( |
| 473 | isExpiredErrorType(errorType) |
| 474 | ? 'Remote Control session has expired. Please restart with `claude remote-control` or /remote-control.' |
| 475 | : `${context}: Access denied (403)${detail ? `: ${detail}` : ''}. Check your organization permissions.`, |
| 476 | 403, |
| 477 | errorType, |
| 478 | ) |
| 479 | case 404: |
| 480 | throw new BridgeFatalError( |
| 481 | detail ?? |
| 482 | `${context}: Not found (404). Remote Control may not be available for this organization.`, |
| 483 | 404, |
| 484 | errorType, |
| 485 | ) |
| 486 | case 410: |
| 487 | throw new BridgeFatalError( |
| 488 | detail ?? |
| 489 | 'Remote Control session has expired. Please restart with `claude remote-control` or /remote-control.', |
| 490 | 410, |
| 491 | errorType ?? 'environment_expired', |
| 492 | ) |
| 493 | case 429: |
| 494 | throw new Error(`${context}: Rate limited (429). Polling too frequently.`) |
| 495 | default: |
| 496 | throw new Error( |
| 497 | `${context}: Failed with status ${status}${detail ? `: ${detail}` : ''}`, |
| 498 | ) |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | /** Check whether an error type string indicates a session/environment expiry. */ |
| 503 | export function isExpiredErrorType(errorType: string | undefined): boolean { |
no test coverage detected