error handling for tracked players having no match found
This commit is contained in:
@@ -217,16 +217,11 @@ type MatchResponse struct {
|
||||
TickRate float64 `json:"tick_rate,omitempty"`
|
||||
}
|
||||
|
||||
type (
|
||||
AuthcodeUnauthorizedError struct {
|
||||
error
|
||||
}
|
||||
AuthcodeRateLimitError struct {
|
||||
error
|
||||
}
|
||||
SharecodeNoMatchError struct {
|
||||
error
|
||||
}
|
||||
var (
|
||||
SharecodeNoMatchError = errors.New("sharecode not provided")
|
||||
AuthcodeRateLimitError = errors.New("temporary rate-limited/unavailable")
|
||||
AuthcodeUnauthorizedError = errors.New("authcode unauthorized")
|
||||
NoMatchError = errors.New("no match found")
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -485,7 +480,7 @@ func IsAuthCodeValid(player *ent.Player, apiKey string, shareCode string, authCo
|
||||
if shareCode == "" {
|
||||
tMatch, err = player.QueryMatches().Order(ent.Asc(match.FieldDate)).First(context.Background())
|
||||
if err != nil {
|
||||
return false, SharecodeNoMatchError{errors.New("sharecode not provided")}
|
||||
return false, SharecodeNoMatchError
|
||||
}
|
||||
|
||||
_, err := getNextShareCode(tMatch.ShareCode, apiKey, authCode, player.ID, rl)
|
||||
@@ -505,11 +500,17 @@ func IsAuthCodeValid(player *ent.Player, apiKey string, shareCode string, authCo
|
||||
func GetNewShareCodesForPlayer(player *ent.Player, apiKey string, rl *rate.Limiter) ([]string, error) {
|
||||
latestMatch, err := player.QueryMatches().Order(ent.Desc(match.FieldDate)).First(context.Background())
|
||||
if err != nil {
|
||||
if ent.IsNotFound(err) {
|
||||
return nil, NoMatchError
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
oldestMatch, err := player.QueryMatches().Order(ent.Asc(match.FieldDate)).First(context.Background())
|
||||
if err != nil {
|
||||
if ent.IsNotFound(err) {
|
||||
return nil, NoMatchError
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -561,13 +562,13 @@ func getNextShareCode(lastCode string, apiKey string, authCode string, steamId u
|
||||
case http.StatusAccepted:
|
||||
return "n/a", nil
|
||||
case http.StatusTooManyRequests:
|
||||
return "", AuthcodeRateLimitError{errors.New("temporary ratelimited")}
|
||||
return "", AuthcodeRateLimitError
|
||||
case http.StatusServiceUnavailable:
|
||||
return "", AuthcodeRateLimitError{errors.New("temporary unavailable")}
|
||||
return "", AuthcodeRateLimitError
|
||||
case http.StatusPreconditionFailed:
|
||||
return "", SharecodeNoMatchError{errors.New("sharecode not from player history")}
|
||||
return "", SharecodeNoMatchError
|
||||
case http.StatusForbidden:
|
||||
return "", AuthcodeUnauthorizedError{errors.New("authcode unauthorized")}
|
||||
return "", AuthcodeUnauthorizedError
|
||||
case http.StatusOK:
|
||||
break
|
||||
default:
|
||||
|
Reference in New Issue
Block a user