StatusForTaskError maps task-domain, workspace, and session failures to transport statuses.
(err error)
| 348 | |
| 349 | // StatusForTaskError maps task-domain, workspace, and session failures to transport statuses. |
| 350 | func StatusForTaskError(err error) int { |
| 351 | switch { |
| 352 | case err == nil: |
| 353 | return http.StatusOK |
| 354 | case errors.Is(err, taskpkg.ErrValidation), |
| 355 | errors.Is(err, taskpkg.ErrInvalidScopeBinding), |
| 356 | errors.Is(err, taskpkg.ErrImmutableField): |
| 357 | return http.StatusBadRequest |
| 358 | case errors.Is(err, taskpkg.ErrPayloadTooLarge): |
| 359 | return http.StatusRequestEntityTooLarge |
| 360 | case errors.Is(err, taskpkg.ErrPermissionDenied): |
| 361 | return http.StatusForbidden |
| 362 | case errors.Is(err, taskpkg.ErrForbiddenOperatorAction): |
| 363 | return http.StatusForbidden |
| 364 | case errors.Is(err, taskpkg.ErrForceOpRateLimited): |
| 365 | return http.StatusTooManyRequests |
| 366 | case errors.Is(err, taskpkg.ErrForceOpRequiresReason), |
| 367 | errors.Is(err, taskpkg.ErrRetryChainTooDeep), |
| 368 | errors.Is(err, taskpkg.ErrBulkTooLarge): |
| 369 | return http.StatusUnprocessableEntity |
| 370 | case errors.Is(err, errAgentIdentityUnavailable), |
| 371 | errors.Is(err, agentidentity.ErrIdentityLookupUnavailable): |
| 372 | return http.StatusServiceUnavailable |
| 373 | case errors.Is(err, agentidentity.ErrIdentityUnauthorized): |
| 374 | return http.StatusForbidden |
| 375 | case errors.Is(err, agentidentity.ErrIdentityRequired), |
| 376 | errors.Is(err, agentidentity.ErrIdentityMismatch), |
| 377 | errors.Is(err, agentidentity.ErrIdentityStale): |
| 378 | return http.StatusUnauthorized |
| 379 | case errors.Is(err, taskpkg.ErrTaskNotFound), |
| 380 | errors.Is(err, taskpkg.ErrTaskRunNotFound), |
| 381 | errors.Is(err, taskpkg.ErrTaskDependencyNotFound), |
| 382 | errors.Is(err, taskpkg.ErrTaskBlockNotFound), |
| 383 | errors.Is(err, taskpkg.ErrTaskEventNotFound), |
| 384 | errors.Is(err, taskpkg.ErrTaskRunIdempotencyNotFound), |
| 385 | errors.Is(err, taskpkg.ErrExecutionProfileNotFound), |
| 386 | errors.Is(err, taskpkg.ErrRunReviewNotFound), |
| 387 | errors.Is(err, workspacepkg.ErrWorkspaceNotFound), |
| 388 | errors.Is(err, session.ErrSessionNotFound), |
| 389 | errors.Is(err, store.ErrSessionNotFound), |
| 390 | errors.Is(err, os.ErrNotExist): |
| 391 | return http.StatusNotFound |
| 392 | case errors.Is(err, workspacepkg.ErrWorkspaceRootMissing): |
| 393 | return http.StatusGone |
| 394 | case errors.Is(err, taskpkg.ErrInvalidStatusTransition), |
| 395 | errors.Is(err, taskpkg.ErrConflict), |
| 396 | errors.Is(err, taskpkg.ErrHallucinatedTaskRefs), |
| 397 | errors.Is(err, taskpkg.ErrGraphLimitExceeded), |
| 398 | errors.Is(err, taskpkg.ErrCycleDetected), |
| 399 | errors.Is(err, taskpkg.ErrSessionAlreadyBound), |
| 400 | errors.Is(err, taskpkg.ErrSessionAttachNotAllowed), |
| 401 | errors.Is(err, store.ErrSessionAttachLocked), |
| 402 | errors.Is(err, store.ErrSessionNotAttachable), |
| 403 | errors.Is(err, taskpkg.ErrStaleNetworkChannel), |
| 404 | errors.Is(err, taskpkg.ErrNoClaimableRun), |
| 405 | errors.Is(err, taskpkg.ErrInvalidClaimToken), |
| 406 | errors.Is(err, taskpkg.ErrLeaseExpired), |
| 407 | errors.Is(err, taskpkg.ErrActiveRunLease): |