From 544d6689afc8630a8e5eb3293ad41eebb1a9188d Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 26 Dec 2023 06:45:17 -0600 Subject: [PATCH] Add error types, small comment typo --- errors.go | 12 ++++++++++++ helpers.go | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 errors.go diff --git a/errors.go b/errors.go new file mode 100644 index 0000000..f4945ad --- /dev/null +++ b/errors.go @@ -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) +} diff --git a/helpers.go b/helpers.go index 8190d5f..81d4edf 100644 --- a/helpers.go +++ b/helpers.go @@ -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 {