Skip to content

Commit ff1286a

Browse files
added additional examples
1 parent bb91924 commit ff1286a

File tree

6 files changed

+7524
-87
lines changed

6 files changed

+7524
-87
lines changed

example/browser/index.js

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { Exceptionless } from "../../node_modules/@exceptionless/browser/dist/index.min.js";
1+
import { Exceptionless } from "../../packages/browser/dist/index";
22
import { divide } from "./math.js";
33
import { TextAreaLogger } from "./text-area-logger.js";
44

5-
await Exceptionless.startup(c => {
5+
await Exceptionless.startup((c) => {
66
c.useDebugLogger();
77
c.services.log = new TextAreaLogger("logs", c.services.log);
88

@@ -23,64 +23,91 @@ await Exceptionless.startup(c => {
2323
myPassword: "123456",
2424
customValue: "Password",
2525
value: {
26-
Password: "123456"
27-
}
26+
Password: "123456",
27+
},
2828
};
2929

3030
c.defaultTags.push("Example", "JavaScript");
31-
c.settings["@@error:MediaError"] = "Off"
31+
c.settings["@@error:MediaError"] = "Off";
3232
});
3333

3434
document.addEventListener("DOMContentLoaded", () => {
3535
const elements = document.querySelectorAll(".submit-log");
3636
for (const element of elements) {
3737
element.addEventListener("click", (event) => {
3838
const level = event.target.attributes["data-level"]?.value;
39-
Exceptionless.submitLog("sendEvents", `This is a log message with level: ${level || "<no log level>"}`, level);
39+
Exceptionless.submitLog(
40+
"sendEvents",
41+
`This is a log message with level: ${level || "<no log level>"}`,
42+
level
43+
);
4044
});
4145
}
4246

43-
document.querySelector("#throw-custom-error").addEventListener("click", () => {
44-
throw new CustomError("A Custom Error", 500);
45-
});
47+
document
48+
.querySelector("#throw-custom-error")
49+
.addEventListener("click", () => {
50+
throw new CustomError("A Custom Error", 500);
51+
});
4652

47-
document.querySelector("#throw-division-by-zero-error").addEventListener("click", () => {
48-
divide(10, 0);
49-
});
53+
document
54+
.querySelector("#throw-division-by-zero-error")
55+
.addEventListener("click", () => {
56+
divide(10, 0);
57+
});
5058

51-
document.querySelector("#throw-index-out-of-range").addEventListener("click", () => {
52-
throwIndexOutOfRange();
53-
});
59+
document
60+
.querySelector("#throw-index-out-of-range")
61+
.addEventListener("click", () => {
62+
throwIndexOutOfRange();
63+
});
5464

55-
document.querySelector("#throw-index-out-of-range-custom-stacking").addEventListener("click", () => {
56-
throwIndexOutOfRange(1, true);
57-
});
65+
document
66+
.querySelector("#throw-index-out-of-range-custom-stacking")
67+
.addEventListener("click", () => {
68+
throwIndexOutOfRange(1, true);
69+
});
5870

59-
document.querySelector("#throw-string-error").addEventListener("click", () => {
60-
throwStringError();
61-
});
71+
document
72+
.querySelector("#throw-string-error")
73+
.addEventListener("click", () => {
74+
throwStringError();
75+
});
6276

63-
document.querySelector("#throw-ignored-error").addEventListener("click", () => {
64-
throw new MediaError("An Ignored Exception Type");
65-
});
77+
document
78+
.querySelector("#throw-ignored-error")
79+
.addEventListener("click", () => {
80+
throw new MediaError("An Ignored Exception Type");
81+
});
6682

67-
document.querySelector("#config-settings-log").addEventListener("click", () => {
68-
Exceptionless.config.services.log.info(JSON.stringify(Exceptionless.config.settings));
69-
});
83+
document
84+
.querySelector("#config-settings-log")
85+
.addEventListener("click", () => {
86+
Exceptionless.config.services.log.info(
87+
JSON.stringify(Exceptionless.config.settings)
88+
);
89+
});
7090
});
7191

7292
function throwIndexOutOfRange(indexer, withCustomStacking) {
7393
try {
7494
getNonexistentData(indexer);
7595
} catch (e) {
7696
if (withCustomStacking) {
77-
if (Math.random() < .5) {
78-
Exceptionless.createException(e).setManualStackingKey("MyCustomStackingKey").submit();
97+
if (Math.random() < 0.5) {
98+
Exceptionless.createException(e)
99+
.setManualStackingKey("MyCustomStackingKey")
100+
.submit();
79101
} else {
80-
Exceptionless.createException(e).setManualStackingInfo({
81-
File: "index.js",
82-
Function: "throwIndexOutOfRange"
83-
}, "Custom Index Out Of Range Exception").submit();
102+
Exceptionless.createException(e)
103+
.setManualStackingInfo(
104+
{
105+
File: "index.js",
106+
Function: "throwIndexOutOfRange",
107+
},
108+
"Custom Index Out Of Range Exception"
109+
)
110+
.submit();
84111
}
85112
} else {
86113
Exceptionless.submitException(e);
@@ -112,7 +139,7 @@ class CustomError extends Error {
112139
}
113140

114141
getPromiseValue() {
115-
return new Promise(r => r({ expensive: "call" }));
142+
return new Promise((r) => r({ expensive: "call" }));
116143
}
117144

118145
get getThrowsError() {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"version":17,"settings":{"@@UserAgentBotPatterns":"*bot*,*crawler*,*spider*,*aolbuild*,*teoma*,*yahoo*","@@log:*":"info","@@log:":"info","@@DataExclusions":"*Password*, *Bearer*,"}}

example/express/app.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import express from "express";
2-
const app = express()
2+
const app = express();
33

44
import { Exceptionless } from "@exceptionless/node";
55

6-
await Exceptionless.startup(c => {
6+
await Exceptionless.startup((c) => {
77
c.apiKey = "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw";
88
c.serverUrl = "http://localhost:5000";
99
c.useDebugLogger();
@@ -20,8 +20,8 @@ await Exceptionless.startup(c => {
2020
myPassword: "123456",
2121
customValue: "Password",
2222
value: {
23-
Password: "123456"
24-
}
23+
Password: "123456",
24+
},
2525
};
2626
});
2727

@@ -39,12 +39,23 @@ app.get("/boom", function boom(req, res) {
3939
throw new Error("Boom!!");
4040
});
4141

42-
app.use(function(err, req, res, next) {
43-
Exceptionless.createUnhandledException(err, "express").addRequestInfo(req).submit();
42+
app.get("/trycatch", function trycatch(req, res) {
43+
try {
44+
throw new Error("Caught in try/catch");
45+
} catch (error) {
46+
Exceptionless.submitException(error);
47+
res.status(404).send("Error caught in try/catch");
48+
}
49+
});
50+
51+
app.use(function (err, req, res, next) {
52+
Exceptionless.createUnhandledException(err, "express")
53+
.addRequestInfo(req)
54+
.submit();
4455
res.status(500).send("Something broke!");
4556
});
4657

47-
app.use(function(req, res, next) {
58+
app.use(function (req, res, next) {
4859
Exceptionless.createNotFound(req.originalUrl).addRequestInfo(req).submit();
4960
res.status(404).send("Sorry cant find that!");
5061
});

example/express/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
"scripts": {
1515
"build": "",
1616
"watch": "",
17-
"test": ""
17+
"test": "",
18+
"dev": "nodemon app.js",
19+
"start": "node app.js"
1820
}
1921
}

example/react/src/App.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ class App extends Component {
4545
}
4646
};
4747

48+
unhandledExceptionExample = () => {
49+
throw new Error("Unhandled exception");
50+
};
51+
4852
renderExample = () => {
4953
if (this.state.error) {
5054
throw new Error("I crashed!");
@@ -62,6 +66,14 @@ class App extends Component {
6266
<button onClick={this.throwErrorInComponent}>
6367
Simulate Error
6468
</button>
69+
<div>
70+
<p>
71+
Throw an uncaught error and make sure Exceptionless tracks it.
72+
</p>
73+
<button onClick={this.unhandledExceptionExample}>
74+
Throw unhandled error
75+
</button>
76+
</div>
6577
<p>
6678
The following buttons simulated handled events outside the
6779
component.

0 commit comments

Comments
 (0)