Skip to content

Commit 36bfd0e

Browse files
authored
Merge pull request #260 from jamman99/main
Improve HTTP error status. Close #259
2 parents 02c9340 + ddbebbc commit 36bfd0e

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

errs/httperrors.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,12 @@ func unknownErrorResponse(w http.ResponseWriter, lgr zerolog.Logger, err error)
262262
// httpErrorStatusCode maps an error Kind to an HTTP Status Code
263263
func httpErrorStatusCode(k Kind) int {
264264
switch k {
265-
case Invalid, Exist, NotExist, Private, BrokenLink, Validation, InvalidRequest:
265+
case Invalid, Private, BrokenLink, Validation, InvalidRequest:
266266
return http.StatusBadRequest
267+
case NotExist:
268+
return http.StatusNotFound
269+
case Exist:
270+
return http.StatusConflict
267271
case UnsupportedMediaType:
268272
return http.StatusUnsupportedMediaType
269273
// the zero value of Kind is Other, so if no Kind is present

errs/httperrors_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ func Test_httpErrorStatusCode(t *testing.T) {
2323
args args
2424
want int
2525
}{
26-
{"Exist", args{k: Exist}, http.StatusBadRequest},
27-
{"NotExist", args{k: NotExist}, http.StatusBadRequest},
26+
{"Exist", args{k: Exist}, http.StatusConflict},
27+
{"NotExist", args{k: NotExist}, http.StatusNotFound},
2828
{"Invalid", args{k: Invalid}, http.StatusBadRequest},
2929
{"Private", args{k: Private}, http.StatusBadRequest},
3030
{"BrokenLink", args{k: BrokenLink}, http.StatusBadRequest},

0 commit comments

Comments
 (0)