Skip to content

Commit

Permalink
Correct error msgs in http.go
Browse files Browse the repository at this point in the history
  • Loading branch information
semperos committed Nov 29, 2024
1 parent 556d6e5 commit 4df1ba9
Showing 1 changed file with 46 additions and 47 deletions.
93 changes: 46 additions & 47 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"io"
"net/http"
"net/url"
"reflect"
"strings"
"time"

Expand Down Expand Up @@ -91,7 +90,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"AuthScheme\" "+
"to be a string, but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "BaseURL":
Expand All @@ -102,7 +101,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"BaseURL\" "+
"to be a string, but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "Debug":
Expand All @@ -115,7 +114,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"Debug\" to be 0 or 1, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "DisableWarn":
Expand All @@ -128,7 +127,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"DisableWarn\" "+
"to be 0 or 1 (falsey/truthy), but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "FormData":
Expand All @@ -143,7 +142,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"FormData\" to be a dictionary, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "Header":
Expand All @@ -158,7 +157,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"Header\" to be a dictionary, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "HeaderAuthorizationKey":
Expand All @@ -169,7 +168,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"HeaderAuthorizationKey\" to be a string, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "PathParams":
Expand All @@ -184,7 +183,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"PathParams\" to be a string, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "QueryParam":
Expand All @@ -199,7 +198,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"QueryParam\" to be a dictionary, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "RawPathParams":
Expand All @@ -214,7 +213,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"RawPathParams\" to be a string, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "RetryCount":
Expand All @@ -224,7 +223,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"RetryCount\" to be an integer, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "RetryMaxWaitTimeMilli":
Expand All @@ -234,7 +233,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"RetryMaxWaitTimeMilli\" to be an integer, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "RetryResetReaders":
Expand All @@ -247,7 +246,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"RetryResetReaders\" to be 0 or 1 (falsey/truthy), "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "RetryWaitTimeMilli":
Expand All @@ -258,7 +257,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"RetryWaitTimeMilli\" to be an integer, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "Token":
Expand All @@ -268,7 +267,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
default:
return nil, fmt.Errorf("%v expects \"Token\" to be a string, but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "UserInfo":
Expand Down Expand Up @@ -296,21 +295,21 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects \"UserInfo\" to be a dictionary "+
"with string values, but received a %v: %v",
goalFnName,
reflect.TypeOf(uivs),
userInfoValues.Type(),
uivs)
}
default:
return nil, fmt.Errorf("%v expects \"UserInfo\" to be a dictionary "+
"with string keys, but received a %v: %v",
goalFnName,
reflect.TypeOf(uiks),
uiks)
userInfoKeys.Type(),
userInfoKeys)
}
default:
return nil, fmt.Errorf("%v expects \"UserInfo\" to be a dictionary, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
default:
Expand All @@ -321,7 +320,7 @@ func NewHTTPClient(optionsD *goal.D) (*HTTPClient, error) {
return nil, fmt.Errorf("%v expects a Goal dictionary with string keys, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(va),
va.Type(),
va)
}
return &httpClient, nil
Expand Down Expand Up @@ -403,8 +402,8 @@ func httpMakerDyadic(x goal.V, args []goal.V, methodLower string, methodUpper st
return goal.Panicf("client http.%s url : client must be a dict or ari.HTTPClient instance, "+
"but received a %v: %v",
methodLower,
reflect.TypeOf(clientOpts),
clientOpts)
x.Type(),
x)
}
y := args[0]
urlS, ok := y.BV().(goal.S)
Expand Down Expand Up @@ -434,8 +433,8 @@ func httpMakerTriadic(x goal.V, args []goal.V, methodLower string, methodUpper s
return goal.Panicf("client http.%s url optionsDict : client must be a dict or ari.HTTPClient instance, "+
"but received a %v: %v",
methodLower,
reflect.TypeOf(clientOpts),
clientOpts)
x.Type(),
x)
}
y := args[1]
urlS, ok := y.BV().(goal.S)
Expand Down Expand Up @@ -510,7 +509,7 @@ func augmentRequestWithOptions(req *resty.Request, optionsD *goal.D, methodLower
default:
return nil, fmt.Errorf("%v expects \"Debug\" to be 0 or 1, but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "FormData":
Expand All @@ -525,7 +524,7 @@ func augmentRequestWithOptions(req *resty.Request, optionsD *goal.D, methodLower
return nil, fmt.Errorf("%v expects \"FormData\" to be a dictionary, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "Header":
Expand All @@ -539,7 +538,7 @@ func augmentRequestWithOptions(req *resty.Request, optionsD *goal.D, methodLower
default:
return nil, fmt.Errorf("%v expects \"Header\" to be a dictionary, but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "PathParams":
Expand All @@ -553,7 +552,7 @@ func augmentRequestWithOptions(req *resty.Request, optionsD *goal.D, methodLower
default:
return nil, fmt.Errorf("%v expects \"PathParams\" to be a string, but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "QueryParam":
Expand All @@ -568,7 +567,7 @@ func augmentRequestWithOptions(req *resty.Request, optionsD *goal.D, methodLower
return nil, fmt.Errorf("%v expects \"QueryParam\" to be a dictionary, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
case "RawPathParams":
Expand All @@ -582,7 +581,7 @@ func augmentRequestWithOptions(req *resty.Request, optionsD *goal.D, methodLower
default:
return nil, fmt.Errorf("%v expects \"RawPathParams\" to be a string, but received a %v: %v",
goalFnName,
reflect.TypeOf(value),
value.Type(),
value)
}
default:
Expand All @@ -592,8 +591,8 @@ func augmentRequestWithOptions(req *resty.Request, optionsD *goal.D, methodLower
default:
return nil, fmt.Errorf("%v expects a Goal dictionary with string keys, but received a %v: %v",
goalFnName,
reflect.TypeOf(kas),
kas)
optionsKeys.Type(),
optionsKeys)
}
return req, nil
}
Expand All @@ -619,16 +618,16 @@ func processFormData(goalD *goal.D, goalFnName string) (url.Values, error) {
"to be a dictionary with values that are strings or lists of strings, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(hv),
hv)
formDataValue.Type(),
formDataValue)
}
}
default:
return nil, fmt.Errorf("%v expects \"FormData\" to be a dictionary "+
"with string keys, but received a %v: %v",
goalFnName,
reflect.TypeOf(fdks),
fdks)
formDataKeys.Type(),
formDataKeys)
}
return urlValues, nil
}
Expand All @@ -654,16 +653,16 @@ func processHeader(goalD *goal.D, goalFnName string) (http.Header, error) {
"a dictionary with values that are strings or lists of strings, "+
"but received a %v: %v",
goalFnName,
reflect.TypeOf(hv),
hv)
headerValue.Type(),
headerValue)
}
}
default:
return nil, fmt.Errorf("%v expects \"Header\" to be a dictionary "+
"with string keys, but received a %v: %v",
goalFnName,
reflect.TypeOf(hks),
hks)
headerKeys.Type(),
headerKeys)
}
return header, nil
}
Expand All @@ -687,16 +686,16 @@ func processQueryParam(goalD *goal.D, goalFnName string) (url.Values, error) {
return nil, fmt.Errorf("%v expects \"QueryParam\" to be a dictionary "+
"with values that are strings or lists of strings, but received a %v: %v",
goalFnName,
reflect.TypeOf(hv),
hv)
queryParamValue.Type(),
queryParamValue)
}
}
default:
return nil, fmt.Errorf("%v expects \"QueryParam\" to be a dictionary "+
"with string keys, but received a %v: %v",
goalFnName,
reflect.TypeOf(qpks),
qpks)
queryParamKeys.Type(),
queryParamKeys)
}
return urlValues, nil
}
Expand Down Expand Up @@ -809,7 +808,7 @@ func serverHandleRequest(goalContext *goal.Context, goalHandler goal.V, requestD
d, ok := responseD.BV().(*goal.D)
if !ok {
//nolint:lll // Error message is long.
http.Error(w, fmt.Sprintf("Server Goal handler function must return a dictionary, but received a %q: %v", d.Type(), d), http.StatusInternalServerError)
http.Error(w, fmt.Sprintf("Server Goal handler function must return a dictionary, but received a %q: %v", responseD.Type(), responseD), http.StatusInternalServerError)
return
}
karr := d.KeyArray()
Expand Down Expand Up @@ -851,6 +850,6 @@ func serverHandleRequest(goalContext *goal.Context, goalHandler goal.V, requestD
}
default:
//nolint:lll // Error message is long.
http.Error(w, fmt.Sprintf(`Sever Goal handler function's return value must be a dictionary with string keys, but keys were of type %q: %v`, ks.Type(), ks), http.StatusInternalServerError)
http.Error(w, fmt.Sprintf(`Sever Goal handler function's return value must be a dictionary with string keys, but keys were of type %q: %v`, karr.Type(), karr), http.StatusInternalServerError)
}
}

0 comments on commit 4df1ba9

Please sign in to comment.