From 1645da107d62bf6e3dbc8697139c5861b2a6a321 Mon Sep 17 00:00:00 2001 From: Yaiba <4yaiba@gmail.com> Date: Mon, 1 Apr 2024 17:01:28 -0500 Subject: [PATCH] core: gateway response change --- core/rpc/client/gateway/http/client.go | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/core/rpc/client/gateway/http/client.go b/core/rpc/client/gateway/http/client.go index 75d07433d..a71b536e8 100644 --- a/core/rpc/client/gateway/http/client.go +++ b/core/rpc/client/gateway/http/client.go @@ -81,14 +81,14 @@ func (g *GatewayHttpClient) Auth(ctx context.Context, auth *types.GatewayAuth) e // standard http error(not from the gateway) fallbackErr := errors.New(res.Status) - var r gatewayAuthPostResponse + var r gatewayErrResponse err = json.NewDecoder(res.Body).Decode(&r) if err != nil { return errors.Join(fallbackErr, err) } - if r.Error != "" { - return errors.New(r.Error) + if r.Message != "" { + return errors.New(r.Message) } return nil @@ -120,20 +120,16 @@ func (g *GatewayHttpClient) GetAuthParameter(ctx context.Context) (*types.Gatewa return nil, err } - if r.Error != "" { - return nil, errors.New(r.Error) - } - return r.Result, nil } -// gatewayAuthPostResponse defines the response of POST request for /auth -type gatewayAuthPostResponse struct { - Error string `json:"error"` +// gatewayErrResponse defines the response of gateway error. +type gatewayErrResponse struct { + // to be compatible with google.golang.org/genproto/googleapis/rpc/status.Status + Message string `json:"message"` } // gatewayAuthGetResponse defines the response of GET request for /auth type gatewayAuthGetResponse struct { Result *types.GatewayAuthParameter `json:"result"` - Error string `json:"error"` }