negundo-client/asset/negundo/js/debug.js

70 lines
1.6 KiB
JavaScript
Raw Normal View History

2024-03-13 13:08:37 +00:00
class ErrorHandler
{
constructor(options) {
if ( options ) {
if ( "url" in options ) {
this.url = options['url'];
}
else {
// throw une erreur ici
}
if ( "apikey" in options ) {
this.apikey = options['apikey'];
}
else {
// throw une erreur ici
}
2024-03-13 13:08:37 +00:00
}
this.catchError();
}
catchError() {
2024-03-15 18:14:20 +00:00
console.log(this.url);
2024-03-13 13:08:37 +00:00
window.onerror = function(message, url, line, column, error) {
// build l'url ET l'api key ensemble pour créer l'URL de réception de bug
2024-03-13 13:08:37 +00:00
fetch(this.url ? this.url : window.location.href, {
method: "post",
headers: {
'Accept': "application/json",
'Content-Type': "application/json",
'User-Agent': "NegundoClient/1.0"
},
body: JSON.stringify({
message: message,
url: url,
line: line,
column: column,
stack: error.stack,
location: window.location.toString()
})
}).then( response => response ).then(data => {
console.info("Error reported", data);
});
return false;
}.bind(this);
}
get url() {
return this._url;
}
set url(set) {
return this._url = set;
}
get apikey() {
2024-03-15 18:14:20 +00:00
return this._apikey;
}
set apikey(set) {
2024-03-15 18:14:20 +00:00
return this._apikey = set;
}
2024-03-13 13:08:37 +00:00
}