{"version":3,"sources":["Shared/Static/js/error-handler.js"],"names":["define","require","$","ajax","selenium","i18n","_handleError","exceptionOrString","oOptions","bIsWarning","bSkipServerLog","bSkipUserDisplay","document","cookie","indexOf","oError","message","stack","_normalizeError","finalMessage","genericErrorMessage","notify","icon","type","console","log","oErrorPost","url","window","location","toString","post","JSON","stringify","contentType","catch","err","_asyncLogToServer","err2","exports","handleError","displayError","displayWarning"],"mappings":"AAAAA,OAAO,SAAUC,SACb,IAAIC,EAAID,QAAQ,UAChBA,QAAQ,oBACR,IAAIE,EAAOF,QAAQ,gBACfG,EAAWH,QAAQ,mBACtBI,EAAOJ,QAAQ,QAiDhB,SAASK,EAAaC,EAAmBC,GAIrC,IAAIC,KAFJD,EAAWA,OAEiBC,WAExBC,EAAkB,mBAAoBF,EAAYA,EAASE,eAAiBD,EAC5EE,EAAmBH,EAASG,iBAE5BA,IAG+D,KAA1DC,SAASC,QAAU,IAAIC,QAAQ,wBAEhCH,GAAmB,GAK3B,IACI,IAAII,EA3CZ,SAAyBR,GAErB,IAAIQ,KAWJ,MAV4C,iBAAtBR,EAGlBQ,EAAOC,QAAUT,EAEZA,IAELQ,EAAOC,QAAUT,EAAkBS,QACnCD,EAAOE,MAAQV,EAAkBU,OAE9BF,EA8BUG,CAAgBX,GAG7B,IAAKI,EACL,CACR,IAAIQ,EAAeJ,EAAOC,QAEM,MAA5BX,EAAKe,qBAAgCX,IACxCU,EAAed,EAAKe,oBAAsB,IAAMD,GAErCjB,EAAEmB,QACEC,KAAM,6BACrBN,QAASG,IAGTI,KAAOd,EAAa,UAAY,WAMrBe,SAAWA,QAAQC,MACnBD,QAAQC,IAAIV,EAAOC,SACfD,EAAOE,OACPO,QAAQC,IAAIV,EAAOE,QAItBP,IAGDN,EAASqB,IAAI,QAASV,EAAOC,QAASD,GAhGlD,SAA2BA,GAEvB,IAAIW,GAAeV,QAASD,EAAOC,QAASW,IAAKC,OAAOC,SAASC,YAC7Df,EAAOE,QAEPS,EAAWT,MAAQF,EAAOE,OAK9Bd,EAAK4B,KAAK,eAAgBC,KAAKC,UAAUP,IAFpBQ,YAAa,qBAEkCC,MAAM,SAAUC,GAG5EZ,SAAWA,QAAQC,MAEnBD,QAAQC,IAAI,qCACZD,QAAQC,IAAIW,MAkFZC,CAAkBtB,IAG1B,MAAOuB,GACCd,SAAWA,QAAQC,KACnBD,QAAQC,IAAI,yBAA0Ba,IAMlD,IAAIC,KAaJ,OAZAA,EAAQC,YAAclC,EAGtBiC,EAAQE,aAAe,SAAUlC,GAC7BD,EAAaC,IAIjBgC,EAAQG,eAAiB,SAAUnC,GAC/BD,EAAaC,GAAqBE,YAAY,EAAMC,gBAAgB,KAGjE6B","file":"error-handler.js","sourcesContent":["define(function (require) {\r\n var $ = require(\"jquery\");\r\n require(\"bootstrap.notify\");\r\n var ajax = require(\"ajax-promise\");\r\n var selenium = require(\"selenium-helper\");\r\n\tvar i18n = require(\"i18n\");\r\n\r\n\r\n //post json error server side\r\n function _asyncLogToServer(oError)\r\n {\r\n var oErrorPost = { message: oError.message, url: window.location.toString() };\r\n if (oError.stack)\r\n {\r\n oErrorPost.stack = oError.stack;\r\n }\r\n\r\n var oAjaxOptions = { contentType: 'application/json' };\r\n //encode content as json, otherwise it will be posted as form data and can trigger a \"dangerous request error\" server side\r\n ajax.post('/Error/LogJS', JSON.stringify(oErrorPost), oAjaxOptions).catch(function (err)\r\n {\r\n\r\n if (console && console.log)\r\n {\r\n console.log('Failed to send js error to server');\r\n console.log(err);\r\n }\r\n });\r\n }\r\n\r\n //always return { message : string, stack?:any } so that we dont care if it's a string or an error\r\n function _normalizeError(exceptionOrString)\r\n {\r\n var oError = {};\r\n var isString = typeof exceptionOrString === \"string\";\r\n \r\n if (isString) {\r\n oError.message = exceptionOrString;\r\n }\r\n else if (exceptionOrString)\r\n {\r\n oError.message = exceptionOrString.message;\r\n oError.stack = exceptionOrString.stack;\r\n }\r\n return oError;\r\n }\r\n\r\n\r\n\t/***\r\n\t * affiche une erreur à l'utilisateur et log coté serveur\r\n\t * oOptions : {\tbIsWarning, //affiche le message en warning au lieu de error\r\n *\t\t\t\t\tbSkipServerLog, // ne log pas coté serveur\r\n *\t\t\t\t bSkipUserDisplay // n'affiche pas l'erreur à l'utilisateur (sauf si on a un cookie displayAllErrors=1 )\r\n\t */\r\n function _handleError(exceptionOrString, oOptions)\r\n {\r\n oOptions = oOptions || {};\r\n\r\n var bIsWarning = !!oOptions.bIsWarning;\r\n\t\t//si l'option bSkipServerLog est renseignée, on utilise sa valeur, sinon on skip si le niveau est warning\r\n var bSkipServerLog = ('bSkipServerLog' in oOptions) ? oOptions.bSkipServerLog : bIsWarning;\r\n var bSkipUserDisplay = oOptions.bSkipUserDisplay;\r\n\r\n if (bSkipUserDisplay)\r\n {\r\n\t\t\t//force l'affichage des erreurs\r\n if ((document.cookie || '').indexOf('displayAllErrors=1') !== -1)\r\n {\r\n bSkipUserDisplay = false;\r\n }\r\n }\r\n\r\n\r\n try {\r\n var oError = _normalizeError(exceptionOrString);\r\n\r\n //display error in UI\r\n if (!bSkipUserDisplay)\r\n {\r\n\t\t\t\tvar finalMessage = oError.message;\r\n\r\n\t\t\t\tif (i18n.genericErrorMessage != null && !bIsWarning)\r\n\t\t\t\t\tfinalMessage = i18n.genericErrorMessage + \" \" + finalMessage;\r\n\r\n $.notify({\r\n icon: 'fa fa-exclamation-triangle',\r\n\t\t\t\t\tmessage: finalMessage\r\n },\r\n\t\t\t\t{\r\n\t\t\t\t\ttype: (bIsWarning ? 'warning' : 'danger')\r\n\t\t\t\t});\r\n\r\n }\r\n\r\n //Display avec stack trace dans la console si présente\r\n if (console && console.log) {\r\n console.log(oError.message);\r\n if (oError.stack) {\r\n console.log(oError.stack);\r\n }\r\n }\r\n\r\n if (!bSkipServerLog)\r\n {\r\n //log error for selenium test to check a js error occured\r\n selenium.log('error', oError.message, oError);\r\n\r\n _asyncLogToServer(oError);\r\n }\r\n }\r\n catch (err2) {\r\n if (console && console.log) {\r\n console.log('error in error-handler', err2);\r\n }\r\n }\r\n\r\n }\r\n\r\n var exports = {};\r\n exports.handleError = _handleError;\r\n\t\r\n //Affiche une erreur à l'utilisateur final\r\n exports.displayError = function (exceptionOrString) {\r\n _handleError(exceptionOrString);\r\n\r\n };\r\n\r\n exports.displayWarning = function (exceptionOrString) {\r\n _handleError(exceptionOrString, { bIsWarning: true, bSkipServerLog: true });\r\n };\r\n\r\n return exports;\r\n});\r\n"]}