Skip to content

Commit 6bca6ba

Browse files
committed
Correctly parse Steam Web API errors when authenticating Steam tokens.
1 parent 2940ddb commit 6bca6ba

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
1414
- Correctly register deferred messages sent from authoritative matches.
1515
- Correctly cancel Lua authoritative match context when match initialization fails.
1616
- Improve decoding of Steam authentication responses to correctly unwrap payload.
17+
- Correctly parse Steam Web API errors when authenticating Steam tokens.
1718

1819
## [2.3.0] - 2018-12-31
1920
### Added

social/social.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,18 @@ type SteamProfile struct {
9595
SteamID uint64 `json:"steamid"`
9696
}
9797

98+
// SteamError contains a possible error response from the Steam Web API.
99+
type SteamError struct {
100+
ErrorCode int `json:"errorcode"`
101+
ErrorDesc string `json:"errordesc"`
102+
}
103+
98104
// Unwrapping the SteamProfile
99105
type SteamProfileWrapper struct {
100-
Response struct {
101-
Params SteamProfile `json:"params"`
102-
} `json:"response"`
106+
Response struct {
107+
Params *SteamProfile `json:"params"`
108+
Error *SteamError `json:"error"`
109+
} `json:"response"`
103110
}
104111

105112
// NewClient creates a new Social Client
@@ -445,7 +452,13 @@ func (c *Client) GetSteamProfile(ctx context.Context, publisherKey string, appID
445452
if err != nil {
446453
return nil, err
447454
}
448-
return &profileWrapper.Response.Params, nil
455+
if profileWrapper.Response.Error != nil {
456+
return nil, fmt.Errorf("%v, %v", profileWrapper.Response.Error.ErrorDesc, profileWrapper.Response.Error.ErrorCode)
457+
}
458+
if profileWrapper.Response.Params == nil {
459+
return nil, errors.New("no steam profile")
460+
}
461+
return profileWrapper.Response.Params, nil
449462
}
450463

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

0 commit comments

Comments
 (0)