Skip to content

Commit

Permalink
core: gateway response change
Browse files Browse the repository at this point in the history
  • Loading branch information
Yaiba authored and jchappelow committed Apr 5, 2024
1 parent 5e09973 commit a17e15b
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions core/rpc/client/gateway/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
}

0 comments on commit a17e15b

Please sign in to comment.