-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathApp.jsx
More file actions
89 lines (80 loc) · 2.74 KB
/
App.jsx
File metadata and controls
89 lines (80 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React, { Component } from "react";
import "./App.css";
import { Exceptionless, ExceptionlessErrorBoundary } from "@exceptionless/react";
class App extends Component {
constructor(props) {
super(props);
this.state = {
error: false,
message: "",
errorInfo: ""
};
}
async componentDidMount() {
await Exceptionless.startup((c) => {
c.apiKey = "LhhP1C9gijpSKCslHHCvwdSIz298twx271nTest";
c.serverUrl = "https://localhost:5100";
c.useDebugLogger();
c.defaultTags.push("Example", "React");
});
}
throwErrorInComponent = () => {
this.setState({ error: true });
};
submitMessage = async () => {
const message = "Hello, world!";
this.setState({ message: "", errorInfo: "" });
await Exceptionless.submitLog(message);
this.setState({ message });
};
tryCatchExample = async () => {
try {
this.setState({ message: "", errorInfo: "" });
throw new Error("Caught in the try/catch");
} catch (error) {
this.setState({ errorInfo: error.message });
await Exceptionless.submitException(error);
}
};
unhandledExceptionExample = () => {
throw new Error("Unhandled exception");
};
renderExample = () => {
if (this.state.error) {
throw new Error("I crashed!");
} else {
return (
<div className="App">
<header className="App-header">
<div className="container">
<h1 className="App-title">Exceptionless React Sample</h1>
<p>By pressing the button below, an uncaught error will be thrown inside your component. This will automatically be sent to Exceptionless.</p>
<button onClick={this.throwErrorInComponent}>Simulate Error</button>
<div>
<p>Throw an uncaught error and make sure Exceptionless tracks it.</p>
<button onClick={this.unhandledExceptionExample}>Throw unhandled error</button>
</div>
<p>The following buttons simulated handled events outside the component.</p>
<button onClick={this.submitMessage}>Submit Message</button>
{this.state.message && (
<p>
Message sent to Exceptionless: <code>{this.state.message}</code>
</p>
)}
<button onClick={this.tryCatchExample}>Try/Catch Example</button>
{this.state.errorInfo && (
<p>
Error message sent to Exceptionless: <code>{this.state.errorInfo}</code>
</p>
)}
</div>
</header>
</div>
);
}
};
render() {
return <ExceptionlessErrorBoundary>{this.renderExample()}</ExceptionlessErrorBoundary>;
}
}
export default App;