StatusForMemoryError maps memory-domain errors to transport statuses.
(err error)
| 227 | |
| 228 | // StatusForMemoryError maps memory-domain errors to transport statuses. |
| 229 | func StatusForMemoryError(err error) int { |
| 230 | switch { |
| 231 | case err == nil: |
| 232 | return http.StatusOK |
| 233 | case errors.Is(err, ErrMemoryUnsupported): |
| 234 | return http.StatusNotImplemented |
| 235 | case errors.Is(err, ErrMemoryRejected): |
| 236 | return http.StatusUnprocessableEntity |
| 237 | case errors.Is(err, os.ErrNotExist): |
| 238 | return http.StatusNotFound |
| 239 | case errors.Is(err, memory.ErrValidation): |
| 240 | return http.StatusBadRequest |
| 241 | default: |
| 242 | return http.StatusInternalServerError |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | // StatusForResourceError maps desired-state resource failures to transport statuses. |
| 247 | func StatusForResourceError(err error) int { |