Skip to content

Commit d0b4305

Browse files
author
Mathieu Grzybek
committed
[api] deal with HTTP error codes
1 parent 1e23f86 commit d0b4305

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

utils/api.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package utils
22

33
import (
4+
"fmt"
45
"io"
56
"net/http"
7+
"errors"
68
)
79

810
func CallAPIGet(url, token string) ([]byte, error) {
@@ -15,6 +17,9 @@ func CallAPIGet(url, token string) ([]byte, error) {
1517
if e != nil {
1618
return []byte(""), e
1719
}
20+
if res.StatusCode != 200 {
21+
return []byte(""), errors.New(fmt.Sprintf("API returned code %d", res.StatusCode))
22+
}
1823
body, e := io.ReadAll(res.Body)
1924

2025
return body, e

0 commit comments

Comments
 (0)