1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: minor code style and cleanup

This commit is contained in:
Ferdinand Mütsch
2023-07-09 20:16:34 +02:00
parent 3063e80692
commit 45a003185e
5 changed files with 43 additions and 41 deletions

View File

@@ -2,6 +2,7 @@ package utils
import (
"errors"
"fmt"
"net/http"
"regexp"
"strconv"
@@ -85,3 +86,13 @@ func ParseUserAgent(ua string) (string, string, error) {
}
return groups[0][1], groups[0][2], nil
}
func RaiseForStatus(res *http.Response, err error) (*http.Response, error) {
if err != nil {
return res, err
}
if res.StatusCode >= 400 {
return res, fmt.Errorf("got response status %d for '%s %s'", res.StatusCode, res.Request.Method, res.Request.URL.String())
}
return res, nil
}