* Map a thrown error to the right envelope. See module header for the table. * * `TaskAlreadyFinishedError` is a SPECIAL case — REST.md §3.7 mandates * envelope `code: 40904` + `data: {cancelled: false}` for the idempotent * cancellation shape.
(
reply: { send(payload: unknown): unknown },
requestId: string,
err: unknown,
)
| 215 | * cancellation shape. |
| 216 | */ |
| 217 | function sendMappedError( |
| 218 | reply: { send(payload: unknown): unknown }, |
| 219 | requestId: string, |
| 220 | err: unknown, |
| 221 | ): void { |
| 222 | if (err instanceof TaskAlreadyFinishedError) { |
| 223 | reply.send({ |
| 224 | code: ErrorCode.TASK_ALREADY_FINISHED, |
| 225 | msg: err.message, |
| 226 | data: { cancelled: false }, |
| 227 | request_id: requestId, |
| 228 | details: { current_status: err.currentStatus }, |
| 229 | }); |
| 230 | return; |
| 231 | } |
| 232 | if (err instanceof TaskNotFoundError) { |
| 233 | reply.send(errEnvelope(ErrorCode.TASK_NOT_FOUND, err.message, requestId)); |
| 234 | return; |
| 235 | } |
| 236 | if (err instanceof SessionNotFoundError) { |
| 237 | reply.send(errEnvelope(ErrorCode.SESSION_NOT_FOUND, err.message, requestId)); |
| 238 | return; |
| 239 | } |
| 240 | throw err; |
| 241 | } |
no test coverage detected