| 83 | } |
| 84 | |
| 85 | private async handleErrorResponse(response: Response, endpoint: string): Promise<never> { |
| 86 | let responseBody: unknown |
| 87 | |
| 88 | try { |
| 89 | responseBody = await response.json() |
| 90 | } catch { |
| 91 | responseBody = await response.text() |
| 92 | } |
| 93 | |
| 94 | switch (response.status) { |
| 95 | case 401: |
| 96 | throw new AuthenticationError() |
| 97 | case 404: |
| 98 | if (endpoint.includes("/share")) { |
| 99 | throw new TaskNotFoundError() |
| 100 | } |
| 101 | throw new CloudAPIError(`Resource not found: ${endpoint}`, 404, responseBody) |
| 102 | default: |
| 103 | throw new CloudAPIError( |
| 104 | `HTTP ${response.status}: ${response.statusText}`, |
| 105 | response.status, |
| 106 | responseBody, |
| 107 | ) |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | async shareTask(taskId: string, visibility: ShareVisibility = "organization"): Promise<ShareResponse> { |
| 112 | this.log(`[CloudAPI] Sharing task ${taskId} with visibility: ${visibility}`) |