Skip to content

Commit

Permalink
Adding slices contains
Browse files Browse the repository at this point in the history
  • Loading branch information
MovieStoreGuy committed Oct 24, 2024
1 parent 00bf849 commit 0ba2ca9
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"slices"
)

// ResponseError captures the error details
Expand All @@ -22,11 +23,8 @@ func newResponseError(resp *http.Response, target int, targets ...int) error {
return nil
}

// Once upgraded to go 1.22+, replace for slices.Contains
for _, code := range append([]int{target}, targets...) {
if resp.StatusCode == code {
return nil
}
if slices.Contains(append([]int{target}, targets...), resp.StatusCode) {
return nil
}

details, _ := io.ReadAll(resp.Body)
Expand Down

0 comments on commit 0ba2ca9

Please sign in to comment.