diff --git a/CHANGELOG.md b/CHANGELOG.md index 310eb21af0816e25efd25a30b6da1e724d35c145..b657da5f3c3358b2a8d7b64a5460dd80a95d829d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/social/social.go b/social/social.go index f393892904efb178cf7042bf13b678642187a9d9..851114d4b25a29f7a5ddc36649745580f2ce543e 100644 --- a/social/social.go +++ b/social/social.go @@ -95,11 +95,18 @@ 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"` - } `json:"response"` + Response struct { + Params *SteamProfile `json:"params"` + Error *SteamError `json:"error"` + } `json:"response"` } // NewClient creates a new Social Client @@ -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 {