Add error types, small comment typo

This commit is contained in:
2023-12-26 06:45:17 -06:00
parent aaf8b8ebcd
commit 544d6689af
2 changed files with 14 additions and 2 deletions

12
errors.go Normal file
View File

@@ -0,0 +1,12 @@
package main
import "fmt"
type UnexpectedContentTypeError struct {
Expected string
Actual string
}
func (e *UnexpectedContentTypeError) Error() string {
return fmt.Sprintf("Expected content type '%s', received '%s'", e.Expected, e.Actual)
}

View File

@@ -104,8 +104,8 @@ func Nonce() string {
return strconv.Itoa(int(time.Now().UnixMilli()))
}
// doRequest performs & logs the request, logging and returning the response
func doRequest(req *http.Request) (*http.Response, error) {
// DoRequest performs & logs the request, logging and returning the response
func DoRequest(req *http.Request) (*http.Response, error) {
log.Debug().Str("method", strings.TrimRight(req.Method, " ")).Str("url", req.URL.String()).Str("query", req.URL.RawQuery).Str("content-type", req.Header.Get("Content-Type")).Msg("Request")
res, err := client.Do(req)
if err != nil {