From 6bca6bae7d283f9fe9ad2027b25d8ad5a7fc21f3 Mon Sep 17 00:00:00 2001 From: Andrei Mihu <andrei@heroiclabs.com> Date: Fri, 4 Jan 2019 16:54:17 +0000 Subject: [PATCH] Correctly parse Steam Web API errors when authenticating Steam tokens. --- CHANGELOG.md | 1 + social/social.go | 21 +++++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 310eb21af..b657da5f3 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 f39389290..851114d4b 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 { -- GitLab