From 66a3854a2459015f35fa22771984b8e33a2476d7 Mon Sep 17 00:00:00 2001 From: Daniel Scalzi Date: Sat, 14 Apr 2018 18:42:45 -0400 Subject: [PATCH] Better error handling with Mojang REST api. Added handling for when there is no internet connection or Mojang's auth server is unreachable to both the login and status modules. --- app/assets/js/actionbinder.js | 9 +++--- app/assets/js/mojang.js | 55 +++++++++++++++++++++++++---------- app/login.ejs | 34 ++++++++++++++++++++-- 3 files changed, 74 insertions(+), 24 deletions(-) diff --git a/app/assets/js/actionbinder.js b/app/assets/js/actionbinder.js index 965be884..2daa2962 100644 --- a/app/assets/js/actionbinder.js +++ b/app/assets/js/actionbinder.js @@ -62,8 +62,8 @@ document.addEventListener('readystatechange', function(){ // Update Mojang Status Color const refreshMojangStatuses = async function(){ console.log('Refreshing Mojang Statuses..') + let status = 'grey' try { - let status = 'grey' const statuses = await Mojang.status() greenCount = 0 for(let i=0; i err.cause | err.error | err.errorMessage + // Node error => err.code | err.message if(err.cause != null && err.cause === 'UserMigratedException') { return { title: 'Error During Login:
Invalid Credentials', @@ -202,11 +204,37 @@ } } } + } else { + // Request errors (from Node). + if(err.code != null){ + if(err.code === 'ENOENT'){ + // No Internet. + return { + title: 'Error During Login:
No Internet Connection', + desc: 'You must be connected to the internet in order to login. Please connect and try again.' + } + } else if(err.code === 'ENOTFOUND'){ + // Could not reach server. + return { + title: 'Error During Login:
Authentication Server Offline', + desc: 'Mojang\'s authentication server is currently offline or unreachable. Please wait a bit and try again. You can check the status of the server on Mojang\'s help portal.' + } + } + } } } - return { - title: err.error, - desc: err.errorMessage + if(err.message != null){ + // Unknown error with request. + return { + title: 'Error During Login:
Unknown Error', + desc: err.message + } + } else { + // Unknown Mojang error. + return { + title: err.error, + desc: err.errorMessage + } } }