From bbdbe7e5996add8160c479de31c03e757bb4b65a Mon Sep 17 00:00:00 2001 From: Nick Krecklow Date: Mon, 11 May 2020 18:58:47 -0500 Subject: [PATCH] simplify error rendering logic --- assets/js/scale.js | 2 +- assets/js/servers.js | 20 +++++++++----------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/assets/js/scale.js b/assets/js/scale.js index 7a82368..ef1b9e0 100644 --- a/assets/js/scale.js +++ b/assets/js/scale.js @@ -38,7 +38,7 @@ export class RelativeScale { } } - if (max === Number.MAX_VALUE) { + if (max === Number.MIN_VALUE) { max = 0 } diff --git a/assets/js/servers.js b/assets/js/servers.js index b39623b..6779b56 100644 --- a/assets/js/servers.js +++ b/assets/js/servers.js @@ -244,22 +244,20 @@ export class ServerRegistration { const playerCountLabelElement = document.getElementById('player-count_' + 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 playerCountLabelElement.style.display = 'none' errorElement.style.display = 'block' - let errorMessage + errorElement.innerText = ping.error.message + } 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 (ping.error) { - errorMessage = ping.error.message - } else if (typeof ping.playerCount !== 'number') { - // 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 - errorMessage = 'Failed to ping' - } - - errorElement.innerText = errorMessage + // 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 + errorElement.innerText = 'Failed to ping' } else if (typeof ping.playerCount === 'number') { // Ensure the player-count element is visible and hide the error element playerCountLabelElement.style.display = 'block'