Skip to content

Commit

Permalink
Correctly parse Steam Web API errors when authenticating Steam tokens.
Browse files Browse the repository at this point in the history
  • Loading branch information
zyro committed Jan 4, 2019
1 parent 2940ddb commit 6bca6ba
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions social/social.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 6bca6ba

Please sign in to comment.