4 Commits
2 changed files with 29 additions and 9 deletions

No files matched your search

+19 -9
View File
@@ -1,4 +1,7 @@
class ErrorHandler { class ErrorHandler {
#unhandledRection = false
constructor(options) { constructor(options) {
if (!options) throw new Error("Options not provided"); if (!options) throw new Error("Options not provided");
if (!options.url) throw new Error("URL is required"); if (!options.url) throw new Error("URL is required");
@@ -37,19 +40,19 @@ class ErrorHandler {
}; };
window.addEventListener('unhandledrejection', event => { window.addEventListener('unhandledrejection', event => {
if (! this.#unhandledRection) {
this.#unhandledRection = true;
this.reportError(event.reason.toString(), document.location.href, 0, 0, event.reason.stack, 'Promise Rejection'); this.reportError(event.reason.toString(), document.location.href, 0, 0, event.reason.stack, 'Promise Rejection');
}
}); });
this.createErrorAgain();
} }
async reportError(message, url, line, column, stack, type = 'JavaScript Error') { async reportError(message, url, line, column, stack, type = 'JavaScript Error') {
await new Promise(r => setTimeout(r, 2000)); await new Promise(r => setTimeout(r, 2000));
fetch(this.url ? `${this.url}/${this.apikey}` : window.location.href, { try {
method: "POST", const response = await fetch(this.url ? `${this.url}/${this.apikey}` : window.location.href, {
method: "PUT",
headers: { headers: {
'Accept': "application/json", 'Accept': "application/json",
'Content-Type': "application/json" 'Content-Type': "application/json"
@@ -64,7 +67,16 @@ class ErrorHandler {
file: window.location.href, file: window.location.href,
source: await this.getSourceCode(url, line), source: await this.getSourceCode(url, line),
}) })
}).then(response => response.json()).then(console.info); });
if (response.ok) {
this.#unhandledRection = false;
return await response.json()
}
} catch (error) {
console.error('CORS or network error:', error.message);
}
} }
async getSourceCode(url, errorLineNumber) { async getSourceCode(url, errorLineNumber) {
@@ -95,8 +107,6 @@ class ErrorHandler {
obj.file = match[2]; obj.file = match[2];
obj.line = match[3]; obj.line = match[3];
// column would be match[4] if needed // column would be match[4] if needed
console.log(match);
} }
// Remove undefined/empty values // Remove undefined/empty values
+10
View File
@@ -4,6 +4,16 @@ use Negundo\Client\{ SoftwareConfig, Dump, Task, NegundoMiddleware };
use function DI\{ autowire, create, get, add }; use function DI\{ autowire, create, get, add };
if (! function_exists('getenvonce')) {
function getenvonce(string $name) : array|string|false
{
$value = getenv($name);
unset($_ENV[$name], $_SERVER[$name]);
putenv($name . "=");
return $value;
}
}
return [ return [
SoftwareConfig::class => create(SoftwareConfig::class)->constructor( SoftwareConfig::class => create(SoftwareConfig::class)->constructor(
serverUrl: getenvonce('NEGUNDO_SERVER'), serverUrl: getenvonce('NEGUNDO_SERVER'),