Skip to content

Commit b0f0d55

Browse files
committed
Updated the browser sample
1 parent b1782a2 commit b0f0d55

File tree

4 files changed

+93
-80
lines changed

4 files changed

+93
-80
lines changed

example/browser/index.html

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,30 @@
11
<!DOCTYPE html>
22
<html>
3-
<head lang="en">
4-
<meta charset="UTF-8">
5-
<meta http-equiv="X-UA-Compatible" content="IE=Edge">
6-
<title>Exceptionless Test</title>
7-
</head>
8-
<body>
9-
<script type="module" src="index.js"></script>
10-
<script type="module" src="divide.js"></script>
3+
<head lang="en">
4+
<meta charset="UTF-8" />
5+
<title>Exceptionless Test</title>
6+
</head>
7+
<body>
8+
<h1>Error Submission</h1>
9+
<button id="throw-custom-error">Throw custom error</button>
10+
<button id="throw-division-by-zero-error">Throw division by zero</button>
11+
<button id="throw-index-out-of-range">Throw index out of range</button>
12+
<button id="throw-index-out-of-range-custom-stacking">Throw index out of range (Custom Stacking)</button>
13+
<button id="throw-string-error">Throw string error</button>
14+
<button id="throw-ignored-error">Throw ignored error</button>
15+
<button onclick="throwReferenceError('function-does-exist')">Throw uncaught reference error</button>
1116

12-
<button onclick="throwDivisionByZero()">Division By Zero</button>
13-
<button onclick="throwIndexOutOfRange(100)">Index Out Of Range</button>
14-
<button onclick="throwIndexOutOfRange(100, true)">Index Out Of Range with custom stacking</button>
15-
<button onclick="throwStringError()">Throw String Message</button>
16-
<button onclick="sendEvents(10)">Send 10 random events</button>
17-
<button onclick="sendEvents(100)">Send 100 random events</button>
18-
<button onclick="sendEvents(100, 0)">Send 100 exceptions</button>
19-
<br />
20-
<br />
21-
<button onclick="sendEvents(100, 1)">Send 100 log messages</button>
22-
<button onclick="sendEvents(1, 1)">Send trace log event</button>
23-
<button onclick="sendEvents(1, 2)">Send debug log event</button>
24-
<button onclick="sendEvents(1, 3)">Send info log event</button>
25-
<button onclick="sendEvents(1, 4)">Send warn log event</button>
26-
<button onclick="sendEvents(1, 5)">Send error log event</button>
27-
<br />
28-
<br />
29-
<button onclick="logClientConfigurationSettings()">Log Client Configuration Settings (settings sent from server)</button>
30-
</body>
17+
<h1>Log Submission</h1>
18+
<button class="submit-log">Submit log event</button>
19+
<button class="submit-log" data-level="trace">Submit trace log event</button>
20+
<button class="submit-log" data-level="debug">Submit debug log event</button>
21+
<button class="submit-log" data-level="info">Submit info log event</button>
22+
<button class="submit-log" data-level="warn">Submit warn log event</button>
23+
<button class="submit-log" data-level="error">Submit error log event</button>
24+
25+
<h1>Diagnostics</h1>
26+
<button id="config-settings-log">Log Client Configuration Settings (settings sent from server)</button>
27+
28+
<script type="module" src="index.js"></script>
29+
</body>
3130
</html>

example/browser/index.js

Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Exceptionless } from "../../node_modules/@exceptionless/browser/dist/index.min.js";
2+
import { divide } from "./math.js";
23

34
Exceptionless.startup(c => {
45
c.apiKey = "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw";
@@ -24,81 +25,94 @@ Exceptionless.startup(c => {
2425
};
2526

2627
c.defaultTags.push("Example", "JavaScript");
28+
c.settings["@@error:MediaError"] = "Off"
2729
});
2830

29-
function getNonexistentData() {
30-
/* random comment */ nonexistentArray[arguments[0]]; // second random comment;
31-
}
32-
33-
function sendEvents(numberToSends, eventType) {
34-
for (var index = 0; index < numberToSends; index++) {
35-
switch (eventType || getRandomInt(0, 5)) {
36-
case 0: {
37-
throwIndexOutOfRange();
38-
break;
39-
}
40-
case 1: {
41-
exceptionless.ExceptionlessClient.default.submitLog("sendEvents", "This is a test trace message", "trace");
42-
break;
43-
}
44-
case 2: {
45-
exceptionless.ExceptionlessClient.default.submitLog("sendEvents", "This is a test debug message", "debug");
46-
break;
47-
}
48-
case 3: {
49-
exceptionless.ExceptionlessClient.default.submitLog("sendEvents", "This is a test info message", "info");
50-
break;
51-
}
52-
case 4: {
53-
exceptionless.ExceptionlessClient.default.submitLog("sendEvents", "This is a test warn message", "warn");
54-
break;
55-
}
56-
case 5: {
57-
exceptionless.ExceptionlessClient.default.submitLog("sendEvents", "This is a test error message", "error");
58-
break;
59-
}
60-
}
31+
document.addEventListener("DOMContentLoaded", () => {
32+
const elements = document.querySelectorAll(".submit-log");
33+
for (const element of elements) {
34+
element.addEventListener("click", (event) => {
35+
const level = event.target.attributes["data-level"];
36+
Exceptionless.submitLog("sendEvents", `This is a log message with level: ${level || "<no log level>"}`, level);
37+
});
6138
}
62-
}
6339

64-
function getRandomInt(min, max) {
65-
exceptionless.ExceptionlessClient.default.submitLog("getting random int min:" + min + " max:" + max);
66-
return Math.floor(Math.random() * (max - min + 1)) + min;
67-
}
40+
document.querySelector("#throw-custom-error").addEventListener("click", () => {
41+
throw new CustomError("A Custom Error", 500);
42+
});
6843

69-
function throwDivisionByZero() {
70-
return divide(10, 0);
71-
}
44+
document.querySelector("#throw-division-by-zero-error").addEventListener("click", () => {
45+
divide(10, 0);
46+
});
7247

73-
function throwStringError() {
74-
return throwStringErrorImpl("string error message");
75-
}
48+
document.querySelector("#throw-index-out-of-range").addEventListener("click", () => {
49+
throwIndexOutOfRange();
50+
});
51+
52+
document.querySelector("#throw-index-out-of-range-custom-stacking").addEventListener("click", () => {
53+
throwIndexOutOfRange(1, true);
54+
});
55+
56+
document.querySelector("#throw-string-error").addEventListener("click", () => {
57+
throwStringError();
58+
});
59+
60+
document.querySelector("#throw-ignored-error").addEventListener("click", () => {
61+
throw new MediaError("An Ignored Exception Type");
62+
});
63+
64+
document.querySelector("#config-settings-log").addEventListener("click", () => {
65+
console.log(Exceptionless.config.settings);
66+
});
67+
});
7668

7769
function throwIndexOutOfRange(indexer, withCustomStacking) {
7870
try {
7971
getNonexistentData(indexer);
8072
} catch (e) {
81-
var client = exceptionless.ExceptionlessClient.default;
8273
if (withCustomStacking) {
8374
if (Math.random() < .5) {
84-
client.createException(e).setManualStackingKey("MyCustomStackingKey").submit();
75+
Exceptionless.createException(e).setManualStackingKey("MyCustomStackingKey").submit();
8576
} else {
86-
client.createException(e).setManualStackingInfo({
77+
Exceptionless.createException(e).setManualStackingInfo({
8778
File: "index.js",
8879
Function: "throwIndexOutOfRange"
8980
}, "Custom Index Out Of Range Exception").submit();
9081
}
9182
} else {
92-
client.submitException(e);
83+
Exceptionless.submitException(e);
9384
}
9485
}
9586
}
9687

88+
function getNonexistentData(...args) {
89+
/* random comment */ nonexistentArray[args[0]]; // second random comment;
90+
}
91+
92+
function throwStringError() {
93+
return throwStringErrorImpl("string error message");
94+
}
95+
9796
function throwStringErrorImpl(message) {
98-
throw new Error(message);
97+
throw message;
9998
}
10099

101-
function logClientConfigurationSettings() {
102-
var client = exceptionless.ExceptionlessClient.default;
103-
console.log(client.config.settings);
100+
class CustomError extends Error {
101+
constructor(message, code) {
102+
super(message);
103+
this.name = "CustomError";
104+
this.code = code; // Extra property;
105+
}
106+
107+
getValue() {
108+
return 5;
109+
}
110+
111+
getPromiseValue() {
112+
return new Promise(r => r({ expensive: "call" }));
113+
}
114+
115+
get getThrowsError() {
116+
throw new Error("Not Implemented");
117+
}
104118
}

example/browser/divide.js renamed to example/browser/math.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default function (numerator, denominator) {
1+
export function divide(numerator, denominator) {
22
if (denominator == 0) {
33
throw new Error("Division by zero.");
44
}

example/express/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import express from "express";
22
const app = express()
33

4-
import { Exceptionless } from "@exceptionless/node";
4+
import { Exceptionless } from "../../node_modules/@exceptionless/node/dist/index.js";
55

66
Exceptionless.startup(c => {
77
c.apiKey = "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw";

0 commit comments

Comments
 (0)