StatusForResourceError maps desired-state resource failures to transport statuses.
(err error)
| 245 | |
| 246 | // StatusForResourceError maps desired-state resource failures to transport statuses. |
| 247 | func 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. |
| 275 | func StatusForToolError(err error) int { |