Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
273da35b92 | |||
556e8dd568 | |||
f3573e651b |
21
util.go
21
util.go
@@ -12,6 +12,7 @@ import (
|
|||||||
|
|
||||||
"github.com/unistack-org/micro/v3/client"
|
"github.com/unistack-org/micro/v3/client"
|
||||||
"github.com/unistack-org/micro/v3/errors"
|
"github.com/unistack-org/micro/v3/errors"
|
||||||
|
"github.com/unistack-org/micro/v3/logger"
|
||||||
rutil "github.com/unistack-org/micro/v3/util/reflect"
|
rutil "github.com/unistack-org/micro/v3/util/reflect"
|
||||||
util "github.com/unistack-org/micro/v3/util/router"
|
util "github.com/unistack-org/micro/v3/util/router"
|
||||||
)
|
)
|
||||||
@@ -113,7 +114,7 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint: gocritic
|
// nolint: gocritic, nestif
|
||||||
if _, ok := fieldsmap[t.name]; ok {
|
if _, ok := fieldsmap[t.name]; ok {
|
||||||
switch val.Type().Kind() {
|
switch val.Type().Kind() {
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
@@ -124,8 +125,10 @@ func newPathRequest(path string, method string, body string, msg interface{}, ta
|
|||||||
default:
|
default:
|
||||||
fieldsmap[t.name] = fmt.Sprintf("%v", val.Interface())
|
fieldsmap[t.name] = fmt.Sprintf("%v", val.Interface())
|
||||||
}
|
}
|
||||||
} else if (body == "*" || body == t.name) && method != http.MethodGet && tnmsg.Field(i).CanSet() {
|
} else if (body == "*" || body == t.name) && method != http.MethodGet {
|
||||||
tnmsg.Field(i).Set(val)
|
if tnmsg.Field(i).CanSet() {
|
||||||
|
tnmsg.Field(i).Set(val)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
if val.Type().Kind() == reflect.Slice {
|
if val.Type().Kind() == reflect.Slice {
|
||||||
for idx := 0; idx < val.Len(); idx++ {
|
for idx := 0; idx < val.Len(); idx++ {
|
||||||
@@ -209,7 +212,17 @@ func (h *httpClient) parseRsp(ctx context.Context, hrsp *http.Response, rsp inte
|
|||||||
}
|
}
|
||||||
|
|
||||||
cf, cerr := h.newCodec(ct)
|
cf, cerr := h.newCodec(ct)
|
||||||
if cerr != nil {
|
if hrsp.StatusCode >= 400 && cerr != nil {
|
||||||
|
var buf []byte
|
||||||
|
if hrsp.Body != nil {
|
||||||
|
buf, err = io.ReadAll(hrsp.Body)
|
||||||
|
if err != nil && h.opts.Logger.V(logger.ErrorLevel) {
|
||||||
|
h.opts.Logger.Errorf(ctx, "failed to read body: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// response like text/plain or something else, return original error
|
||||||
|
return errors.New("go.micro.client", string(buf), int32(hrsp.StatusCode))
|
||||||
|
} else if cerr != nil {
|
||||||
return errors.InternalServerError("go.micro.client", cerr.Error())
|
return errors.InternalServerError("go.micro.client", cerr.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user