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
All checks were successful
Build and Push Docker Image / build-and-push (push) Successful in 47s
This commit is contained in:
@@ -4,10 +4,12 @@ import (
|
||||
"InfantrySkillCalculator/models"
|
||||
"InfantrySkillCalculator/utils"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"io"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"sort"
|
||||
)
|
||||
@@ -23,7 +25,7 @@ func GetScoreByPlayerID(c *gin.Context) {
|
||||
}
|
||||
|
||||
score, err := models.PlayerCache.GetScore(player.ID)
|
||||
var statusCode int = http.StatusOK
|
||||
var statusCode = http.StatusOK
|
||||
if err != nil || score == -1 {
|
||||
score, statusCode = GetPlayerScoreNew(player.Name)
|
||||
if score == score && score != -1 { // not NaN
|
||||
@@ -39,7 +41,7 @@ func GetScoreByPlayerID(c *gin.Context) {
|
||||
c.String(200, fmt.Sprintf("%.2f", score))
|
||||
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>")
|
||||
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>")
|
||||
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>")
|
||||
@@ -57,7 +59,7 @@ func GetScoreByPlayerName(c *gin.Context) {
|
||||
c.String(200, fmt.Sprintf("%.2f", score))
|
||||
case 404:
|
||||
c.String(200, "Spieler nicht gefunden!")
|
||||
case 503, 504:
|
||||
case 503, 504, 408:
|
||||
c.String(statusCode, "Tracker nicht erreichbar!")
|
||||
default:
|
||||
c.String(statusCode, "Ungültige Abfrage!")
|
||||
@@ -75,6 +77,9 @@ func GetPlayerScore(playerName string) (float32, int) {
|
||||
|
||||
func GetPlayerScoreNew(playerName string) (float32, int) {
|
||||
playerData, statusCode := getPlayerData(playerName)
|
||||
if statusCode == 408 { // retry once
|
||||
playerData, statusCode = getPlayerData(playerName)
|
||||
}
|
||||
if statusCode != 200 {
|
||||
return -1, statusCode
|
||||
}
|
||||
@@ -95,6 +100,12 @@ func getPlayerData(playerName string) (*models.TrackerDataJSON, int) {
|
||||
|
||||
res, err := c.Do(req)
|
||||
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())
|
||||
return nil, 0
|
||||
}
|
||||
|
||||
@@ -35,8 +35,8 @@
|
||||
let selectedClan = null;
|
||||
|
||||
const submitButton = addPlayerModal.querySelector('button[name="submit"]');
|
||||
const playerName = addPlayerModal.querySelector('#addPlayerClanName');
|
||||
const clanName = addPlayerModal.querySelector('#playerClanName');
|
||||
const playerName = addPlayerModal.querySelector('#addPlayerName');
|
||||
const clanName = addPlayerModal.querySelector('#addPlayerClanName');
|
||||
const errorDiv = addPlayerModal.querySelector('.error-message');
|
||||
const homeClanList = document.getElementById('home-clan');
|
||||
const oppClanList = document.getElementById('opponent-clan');
|
||||
|
||||
Reference in New Issue
Block a user