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

Function StatusForResourceError

internal/api/core/errors.go:247–272  ·  view source on GitHub ↗

StatusForResourceError maps desired-state resource failures to transport statuses.

(err error)

Source from the content-addressed store, hash-verified

245
246// StatusForResourceError maps desired-state resource failures to transport statuses.
247func StatusForResourceError(err error) int {
248 switch {
249 case err == nil:
250 return http.StatusOK
251 case errors.Is(err, resources.ErrPermissionDenied),
252 errors.Is(err, resources.ErrDirectMutationNotAllowed):
253 return http.StatusForbidden
254 case errors.Is(err, resources.ErrConflict),
255 errors.Is(err, resources.ErrSessionNotActive),
256 errors.Is(err, resources.ErrStaleSourceVersion):
257 return http.StatusConflict
258 case errors.Is(err, resources.ErrPayloadTooLarge):
259 return http.StatusRequestEntityTooLarge
260 case errors.Is(err, resources.ErrRateLimited):
261 return http.StatusTooManyRequests
262 case errors.Is(err, resources.ErrNotFound), errors.Is(err, os.ErrNotExist):
263 return http.StatusNotFound
264 case errors.Is(err, resources.ErrValidation),
265 errors.Is(err, resources.ErrInvalidScopeBinding),
266 errors.Is(err, resources.ErrCodecNotFound),
267 errors.Is(err, resources.ErrCodecTypeMismatch):
268 return http.StatusUnprocessableEntity
269 default:
270 return http.StatusInternalServerError
271 }
272}
273
274// StatusForToolError maps registry failures to stable transport statuses.
275func StatusForToolError(err error) int {

Callers 7

nativeResourceToolErrorFunction · 0.92
ListResourcesMethod · 0.85
GetResourceMethod · 0.85
PutResourceMethod · 0.85
DeleteResourceMethod · 0.85

Calls 1

IsMethod · 0.45

Tested by 1