MCPcopy Create free account
hub / github.com/compozy/agh / StatusForTaskError

Function StatusForTaskError

internal/api/core/errors.go:350–412  ·  view source on GitHub ↗

StatusForTaskError maps task-domain, workspace, and session failures to transport statuses.

(err error)

Source from the content-addressed store, hash-verified

348
349// StatusForTaskError maps task-domain, workspace, and session failures to transport statuses.
350func 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):

Callers 15

TestStatusForTaskErrorFunction · 0.92
TestTaskErrorHelpersFunction · 0.85
RequestTaskRunReviewMethod · 0.85
listTaskRunReviewsMethod · 0.85
GetTaskRunReviewMethod · 0.85
ListTasksMethod · 0.85
CreateTaskMethod · 0.85
GetTaskMethod · 0.85
BlockTaskMethod · 0.85
ListTaskBlocksMethod · 0.85

Calls 1

IsMethod · 0.45

Tested by 3

TestStatusForTaskErrorFunction · 0.74
TestTaskErrorHelpersFunction · 0.68