Skip to content

Commit c50470e

Browse files
prometherionmjuraga
authored andcommitted
MINOR: utils: decoding configuration errors to HTTP status code
1 parent 891e0eb commit c50470e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

misc/misc.go

+17
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,25 @@ func ParseTimeout(tOut string) *int64 {
191191
return nil
192192
}
193193

194+
func GetHTTPStatusFromConfErr(err *configuration.ConfError) int {
195+
switch err.Code() {
196+
case configuration.ErrObjectDoesNotExist:
197+
return http.StatusNotFound
198+
case configuration.ErrObjectAlreadyExists:
199+
return http.StatusConflict
200+
case configuration.ErrNoParentSpecified:
201+
return http.StatusBadRequest
202+
default:
203+
return http.StatusInternalServerError
204+
}
205+
}
206+
194207
func GetHTTPStatusFromErr(err error) int {
208+
confError := &configuration.ConfError{}
209+
195210
switch {
211+
case errors.As(err, &confError):
212+
return GetHTTPStatusFromConfErr(confError)
196213
case errors.Is(err, client_errors.ErrAlreadyExists):
197214
return http.StatusConflict
198215
case errors.Is(err, client_errors.ErrNotFound):

0 commit comments

Comments
 (0)