Skip to content
Snippets Groups Projects
Commit b40361e9 authored by Patrick's avatar Patrick
Browse files

fix haven't read error msg

parent 5add5e25
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,10 @@ import (
"time"
)
import (
perrors "github.com/pkg/errors"
)
import (
"github.com/go-resty/resty/v2"
)
......@@ -65,16 +69,22 @@ func NewRestyClient(restOption *rest_interface.RestOptions) *RestyClient {
}
func (rc *RestyClient) Do(restRequest *rest_interface.RestRequest, res interface{}) error {
_, err := rc.client.R().
r, err := rc.client.R().
SetHeader("Content-Type", restRequest.Consumes).
SetHeader("Accept", restRequest.Produces).
SetPathParams(restRequest.PathParams).
SetQueryParams(restRequest.QueryParams).
SetHeaders(restRequest.Headers).
SetBody(restRequest.Body).
SetResult(res).
SetHeaders(restRequest.Headers).
Execute(restRequest.Method, "http://"+path.Join(restRequest.Location, restRequest.Path))
return err
if err != nil {
return perrors.WithStack(err)
}
if r.IsError() {
return perrors.New(r.String())
}
return nil
}
func GetRestyClient(restOptions *rest_interface.RestOptions) rest_interface.RestClient {
......
......@@ -112,6 +112,14 @@ func TestRestInvoker_Invoke(t *testing.T) {
QueryParamsMap: nil,
Body: 0,
}
methodConfigMap["GetUserFive"] = &rest_interface.RestMethodConfig{
InterfaceName: "",
MethodName: "GetUserFive",
Path: "/GetUserFive",
Produces: "*/*",
Consumes: "*/*",
MethodType: "GET",
}
methodConfigMap["GetUser"] = &rest_interface.RestMethodConfig{
InterfaceName: "",
MethodName: "GetUser",
......@@ -175,6 +183,10 @@ func TestRestInvoker_Invoke(t *testing.T) {
assert.NoError(t, res.Error())
assert.NotNil(t, res.Result())
assert.Equal(t, "username", res.Result().(*User).Name)
inv = invocation.NewRPCInvocationWithOptions(invocation.WithMethodName("GetUserFive"), invocation.WithReply(user))
res = invoker.Invoke(context.Background(), inv)
assert.Error(t, res.Error(), "test error")
err = common.ServiceMap.UnRegister(url.Protocol, "com.ikurento.user.UserProvider")
assert.NoError(t, err)
}
......@@ -19,6 +19,7 @@ package rest
import (
"context"
"errors"
"fmt"
"strings"
"testing"
......@@ -173,6 +174,10 @@ func (p *UserProvider) GetUserFour(ctx context.Context, user []interface{}, id s
return u, nil
}
func (p *UserProvider) GetUserFive(ctx context.Context, user []interface{}) (*User, error) {
return nil, errors.New("test error")
}
type User struct {
Id int
Time *time.Time
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment