Add timeout retry (once). Fix add-player modal issue.
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 47s

This commit is contained in:
MaxJa4
2024-01-27 21:48:21 +01:00
parent a4b341f421
commit bf8b1af964
2 changed files with 16 additions and 5 deletions

View File

@@ -4,10 +4,12 @@ import (
"InfantrySkillCalculator/models" "InfantrySkillCalculator/models"
"InfantrySkillCalculator/utils" "InfantrySkillCalculator/utils"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"io" "io"
"math" "math"
"net"
"net/http" "net/http"
"sort" "sort"
) )
@@ -23,7 +25,7 @@ func GetScoreByPlayerID(c *gin.Context) {
} }
score, err := models.PlayerCache.GetScore(player.ID) score, err := models.PlayerCache.GetScore(player.ID)
var statusCode int = http.StatusOK var statusCode = http.StatusOK
if err != nil || score == -1 { if err != nil || score == -1 {
score, statusCode = GetPlayerScoreNew(player.Name) score, statusCode = GetPlayerScoreNew(player.Name)
if score == score && score != -1 { // not NaN if score == score && score != -1 { // not NaN
@@ -39,7 +41,7 @@ func GetScoreByPlayerID(c *gin.Context) {
c.String(200, fmt.Sprintf("%.2f", score)) c.String(200, fmt.Sprintf("%.2f", score))
case 404: case 404:
c.String(200, "<i class=\"bi bi-person-x-fill me-2 text-danger fs-5\" style=\"margin-left: 0.69rem;\" data-bs-action=\"tooltip\" data-bs-title=\"Spieler nicht gefunden\"></i>") c.String(200, "<i class=\"bi bi-person-x-fill me-2 text-danger fs-5\" style=\"margin-left: 0.69rem;\" data-bs-action=\"tooltip\" data-bs-title=\"Spieler nicht gefunden\"></i>")
case 503, 504: case 503, 504, 408:
c.String(statusCode, "<i class=\"bi bi-cloud-slash-fill me-2 text-danger fs-5\" style=\"margin-left: 0.69rem;\"data-bs-action=\"tooltip\" data-bs-title=\"Tracker nicht erreichbar\"></i>") c.String(statusCode, "<i class=\"bi bi-cloud-slash-fill me-2 text-danger fs-5\" style=\"margin-left: 0.69rem;\"data-bs-action=\"tooltip\" data-bs-title=\"Tracker nicht erreichbar\"></i>")
default: default:
c.String(statusCode, "<i class=\"bi bi-exclamation-circle-fill me-2 text-danger fs-5\" style=\"margin-left: 0.69rem;\" data-bs-action=\"tooltip\" data-bs-title=\"Unbekannter Fehler\"></i>") c.String(statusCode, "<i class=\"bi bi-exclamation-circle-fill me-2 text-danger fs-5\" style=\"margin-left: 0.69rem;\" data-bs-action=\"tooltip\" data-bs-title=\"Unbekannter Fehler\"></i>")
@@ -57,7 +59,7 @@ func GetScoreByPlayerName(c *gin.Context) {
c.String(200, fmt.Sprintf("%.2f", score)) c.String(200, fmt.Sprintf("%.2f", score))
case 404: case 404:
c.String(200, "Spieler nicht gefunden!") c.String(200, "Spieler nicht gefunden!")
case 503, 504: case 503, 504, 408:
c.String(statusCode, "Tracker nicht erreichbar!") c.String(statusCode, "Tracker nicht erreichbar!")
default: default:
c.String(statusCode, "Ungültige Abfrage!") c.String(statusCode, "Ungültige Abfrage!")
@@ -75,6 +77,9 @@ func GetPlayerScore(playerName string) (float32, int) {
func GetPlayerScoreNew(playerName string) (float32, int) { func GetPlayerScoreNew(playerName string) (float32, int) {
playerData, statusCode := getPlayerData(playerName) playerData, statusCode := getPlayerData(playerName)
if statusCode == 408 { // retry once
playerData, statusCode = getPlayerData(playerName)
}
if statusCode != 200 { if statusCode != 200 {
return -1, statusCode return -1, statusCode
} }
@@ -95,6 +100,12 @@ func getPlayerData(playerName string) (*models.TrackerDataJSON, int) {
res, err := c.Do(req) res, err := c.Do(req)
if err != nil { if err != nil {
var e net.Error
if errors.As(err, &e) && e.Timeout() {
utils.Logger.Errorf("[SCORE] Request timeout!")
return nil, 408
}
utils.Logger.Errorf("[SCORE] Failed to send request: %s", err.Error()) utils.Logger.Errorf("[SCORE] Failed to send request: %s", err.Error())
return nil, 0 return nil, 0
} }

View File

@@ -35,8 +35,8 @@
let selectedClan = null; let selectedClan = null;
const submitButton = addPlayerModal.querySelector('button[name="submit"]'); const submitButton = addPlayerModal.querySelector('button[name="submit"]');
const playerName = addPlayerModal.querySelector('#addPlayerClanName'); const playerName = addPlayerModal.querySelector('#addPlayerName');
const clanName = addPlayerModal.querySelector('#playerClanName'); const clanName = addPlayerModal.querySelector('#addPlayerClanName');
const errorDiv = addPlayerModal.querySelector('.error-message'); const errorDiv = addPlayerModal.querySelector('.error-message');
const homeClanList = document.getElementById('home-clan'); const homeClanList = document.getElementById('home-clan');
const oppClanList = document.getElementById('opponent-clan'); const oppClanList = document.getElementById('opponent-clan');