httpStatusForModelAdminError maps the typed errors from modeladmin to the HTTP status codes the existing endpoints used to return — keeps the REST contract identical after the refactor.
(err error)
| 99 | // the HTTP status codes the existing endpoints used to return — keeps the |
| 100 | // REST contract identical after the refactor. |
| 101 | func httpStatusForModelAdminError(err error) int { |
| 102 | switch { |
| 103 | case errors.Is(err, modeladmin.ErrNameRequired), |
| 104 | errors.Is(err, modeladmin.ErrEmptyBody), |
| 105 | errors.Is(err, modeladmin.ErrPathSeparator), |
| 106 | errors.Is(err, modeladmin.ErrBadAction), |
| 107 | errors.Is(err, modeladmin.ErrInvalidConfig): |
| 108 | return http.StatusBadRequest |
| 109 | case errors.Is(err, modeladmin.ErrNotFound), |
| 110 | errors.Is(err, modeladmin.ErrConfigFileMissing): |
| 111 | return http.StatusNotFound |
| 112 | case errors.Is(err, modeladmin.ErrPathNotTrusted): |
| 113 | return http.StatusForbidden |
| 114 | case errors.Is(err, modeladmin.ErrConflict): |
| 115 | return http.StatusConflict |
| 116 | default: |
| 117 | return http.StatusInternalServerError |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | // ReloadModelsEndpoint handles reloading model configurations from disk |
| 122 | func ReloadModelsEndpoint(cl *config.ModelConfigLoader, appConfig *config.ApplicationConfig) echo.HandlerFunc { |
no test coverage detected