Commit 6bca6bae authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Correctly parse Steam Web API errors when authenticating Steam tokens.

parent 2940ddb5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Correctly register deferred messages sent from authoritative matches.
- Correctly cancel Lua authoritative match context when match initialization fails.
- Improve decoding of Steam authentication responses to correctly unwrap payload.
- Correctly parse Steam Web API errors when authenticating Steam tokens.

## [2.3.0] - 2018-12-31
### Added
+17 −4
Original line number Diff line number Diff line
@@ -95,10 +95,17 @@ type SteamProfile struct {
	SteamID uint64 `json:"steamid"`
}

// SteamError contains a possible error response from the Steam Web API.
type SteamError struct {
	ErrorCode int    `json:"errorcode"`
	ErrorDesc string `json:"errordesc"`
}

// Unwrapping the SteamProfile
type SteamProfileWrapper struct {
	Response struct {
        Params SteamProfile `json:"params"`
		Params *SteamProfile `json:"params"`
		Error  *SteamError   `json:"error"`
	} `json:"response"`
}

@@ -445,7 +452,13 @@ func (c *Client) GetSteamProfile(ctx context.Context, publisherKey string, appID
	if err != nil {
		return nil, err
	}
	return &profileWrapper.Response.Params, nil
	if profileWrapper.Response.Error != nil {
		return nil, fmt.Errorf("%v, %v", profileWrapper.Response.Error.ErrorDesc, profileWrapper.Response.Error.ErrorCode)
	}
	if profileWrapper.Response.Params == nil {
		return nil, errors.New("no steam profile")
	}
	return profileWrapper.Response.Params, nil
}

func (c *Client) request(ctx context.Context, provider, path string, headers map[string]string, to interface{}) error {