simplify error rendering logic

This commit is contained in:
Nick Krecklow 2020-05-11 18:58:47 -05:00
parent 0c98930d4c
commit bbdbe7e599
No known key found for this signature in database
GPG Key ID: 5F149FDE156FFA94
2 changed files with 10 additions and 12 deletions

@ -38,7 +38,7 @@ export class RelativeScale {
} }
} }
if (max === Number.MAX_VALUE) { if (max === Number.MIN_VALUE) {
max = 0 max = 0
} }

@ -244,22 +244,20 @@ export class ServerRegistration {
const playerCountLabelElement = document.getElementById('player-count_' + this.serverId) const playerCountLabelElement = document.getElementById('player-count_' + this.serverId)
const errorElement = document.getElementById('error_' + this.serverId) const errorElement = document.getElementById('error_' + this.serverId)
if (ping.error || typeof ping.playerCount !== 'number') { if (ping.error) {
// Hide any visible player-count and show the error element // Hide any visible player-count and show the error element
playerCountLabelElement.style.display = 'none' playerCountLabelElement.style.display = 'none'
errorElement.style.display = 'block' errorElement.style.display = 'block'
let errorMessage errorElement.innerText = ping.error.message
if (ping.error) {
errorMessage = ping.error.message
} else if (typeof ping.playerCount !== 'number') { } else if (typeof ping.playerCount !== 'number') {
// Hide any visible player-count and show the error element
playerCountLabelElement.style.display = 'none'
errorElement.style.display = 'block'
// If the frontend has freshly connection, and the server's last ping was in error, it may not contain an error object // If the frontend has freshly connection, and the server's last ping was in error, it may not contain an error object
// In this case playerCount will safely be null, so provide a generic error message instead // In this case playerCount will safely be null, so provide a generic error message instead
errorMessage = 'Failed to ping' errorElement.innerText = 'Failed to ping'
}
errorElement.innerText = errorMessage
} else if (typeof ping.playerCount === 'number') { } else if (typeof ping.playerCount === 'number') {
// Ensure the player-count element is visible and hide the error element // Ensure the player-count element is visible and hide the error element
playerCountLabelElement.style.display = 'block' playerCountLabelElement.style.display = 'block'