From 2352a47ab8dae771ef569ffe46a3ac64fac0caf1 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sun, 8 Jan 2017 16:17:22 +0100 Subject: [PATCH] Improved error functions --- assets/js/common/errors.js | 42 ++++++++++++++++++++++++++--- assets/js/common/functionsSchema.js | 14 +++++++++- assets/js/common/url.js | 5 ++++ assets/js/langs/en.inc.js | 7 +++-- assets/js/langs/fr.inc.js | 6 ++--- corePage/config/dev.config.php | 1 + 6 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 assets/js/common/url.js diff --git a/assets/js/common/errors.js b/assets/js/common/errors.js index b1f151e3..82069e16 100644 --- a/assets/js/common/errors.js +++ b/assets/js/common/errors.js @@ -4,12 +4,47 @@ * @author Pierre HUBERT */ +/** + * Submit an error + * + * @param {String} errorLevel The level of the error + * @param {String} errorMessage The message associated with error + * @param {Integer} errorCode The code of the error + * @param {String} errorData Data associated with error + */ +ComunicWeb.common.error.submitError = function(errorLevel, errorMessage, errorCode, errorData){ + //Prepare API request + var apiURI = "webApp/reportError"; + var params = { + "errorLevel": errorLevel, + "errorMessage": errorMessage, + "errorCode": errorCode, + "errorData": errorData.toSource(), + } + + //Not any next action for now + nextAction = function(){}; + + //Send API request + ComunicWeb.common.network.makeAPIrequest(apiURI, params, nextAction); +} + /** * Handle and show a fatal error * - * @param {String} errorMessage Error message + * @param {String} errorMessage The message associated with error + * @param {Integer} errorCode The code of the error + * @param {String} errorData Data associated with error */ -ComunicWeb.common.error.fatalError = function(errorMessage){ +ComunicWeb.common.error.fatalError = function(errorMessage, errorCode, errorData){ + //Each not defined value is empty by default + if(!errorMessage) + var errorMessage = "Undefined error message"; + if(!errorCode) + var errorCode = 0; + if(!errorData) + var errorData = {}; + //Make a black splash screen var splashScreen = document.createElement("div"); splashScreen.style.position = "fixed"; @@ -20,7 +55,7 @@ ComunicWeb.common.error.fatalError = function(errorMessage){ splashScreen.style.backgroundColor = "#000000"; //Show a message on screen to inform user - var messageElem = ComunicWeb.common.messages.createCalloutElem("Fatal error", "A fatal error occured : " + errorMessage + ". Please try to refresh the page...", "danger"); + var messageElem = ComunicWeb.common.messages.createCalloutElem(lang("__fatal_error"), lang("__fatal_error_explanation", [errorMessage]), "danger"); messageElem.style.position = "relative"; messageElem.style.margin = "auto"; messageElem.style.width = "50%"; @@ -33,4 +68,5 @@ ComunicWeb.common.error.fatalError = function(errorMessage){ document.body.appendChild(splashScreen); //Make an API request to submit error + this.submitError("fatal", errorMessage, errorCode, errorData); } \ No newline at end of file diff --git a/assets/js/common/functionsSchema.js b/assets/js/common/functionsSchema.js index c1baab4d..6b8b1d5e 100644 --- a/assets/js/common/functionsSchema.js +++ b/assets/js/common/functionsSchema.js @@ -65,13 +65,25 @@ var ComunicWeb = { * Error functions */ error:{ + /** + * Submit an error + */ + submitError: function(errorLevel, errorMessage, errorCode, errorData){}, /** * Handle and show a fatal error */ - fatalError: function(errorMessage){}, + fatalError: function(errorMessage, errorCode, errorData){}, }, + /** + * URL functions + */ + url:{ + + }, + + /** * Operations on JS files */ diff --git a/assets/js/common/url.js b/assets/js/common/url.js new file mode 100644 index 00000000..afdcb9ba --- /dev/null +++ b/assets/js/common/url.js @@ -0,0 +1,5 @@ +/** + * URL functions + * + * @author Pierre HUBERT + */ \ No newline at end of file diff --git a/assets/js/langs/en.inc.js b/assets/js/langs/en.inc.js index 50e2efa9..96cbffdf 100644 --- a/assets/js/langs/en.inc.js +++ b/assets/js/langs/en.inc.js @@ -4,8 +4,7 @@ * @author Pierre HUBERT */ ComunicWeb.common.langs.en = { - //Basic messages - "hello": "hello", - - "__number_received_messages": "You have received %p messages", + //Error messages + "__fatal_error": "Fatal error", + "__fatal_error_explanation": "A fatal error occured : %p. Please try to refresh the page...", } \ No newline at end of file diff --git a/assets/js/langs/fr.inc.js b/assets/js/langs/fr.inc.js index 6ff27956..ce6fe2fe 100644 --- a/assets/js/langs/fr.inc.js +++ b/assets/js/langs/fr.inc.js @@ -4,7 +4,7 @@ * @author Pierre HUBERT */ ComunicWeb.common.langs.fr = { - //Basic messages - "hello": "bonjour", - "__number_received_messages": "Vous avez reçu %p messages", + //Error messages + "__fatal_error": "Erreur fatale", + "__fatal_error_explanation": "Une erreur fatale a survenue : %p. Veuillez réessayer de recharger la page...", } \ No newline at end of file diff --git a/corePage/config/dev.config.php b/corePage/config/dev.config.php index 497c1766..ba715d87 100644 --- a/corePage/config/dev.config.php +++ b/corePage/config/dev.config.php @@ -26,6 +26,7 @@ $config['JSfiles'] = array( "%PATH_ASSETS%js/common/errors.js", "%PATH_ASSETS%js/common/messages.js", "%PATH_ASSETS%js/common/langs.js", + "%PATH_ASSETS%js/common/url.js", "%PATH_ASSETS%js/common/jsFiles.js", "%PATH_ASSETS%js/common/debug.js", "%PATH_ASSETS%js/langs/en.inc.js",