Skip to content

Commit 303890b

Browse files
committed
Update Svelte Kit example
1 parent 5f9568f commit 303890b

File tree

5 files changed

+106
-46
lines changed

5 files changed

+106
-46
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,13 @@ If you find a bug or want to contribute a feature, feel free to create a pull re
260260
npm install
261261
```
262262

263-
4. Build the project by running the following gulp command.
263+
4. Build the project by running the following command.
264264

265265
```sh
266266
npm run build
267267
```
268268

269-
5. Test the project by running the following gulp command.
269+
5. Test the project by running the following command.
270270

271271
```sh
272272
npm run test

example/svelte-kit/README.md

+9-35
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,12 @@
1-
# create-svelte
1+
## Exceptionless Svelte Kit Example
22

3-
Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte).
3+
This example shows how to use the `@exceptionless/browser` package for client side Svelte Kit and `@exceptionless/node` for server side Svelte Kit. These is both
4+
a client side error hook `hooks.client.js` and a server side error hook `hooks.server.js`.
45

5-
## Creating a project
6+
To run locally, follow these steps:
67

7-
If you're seeing this, you've probably already done this step. Congrats!
8-
9-
```bash
10-
# create a new project in the current directory
11-
npm create svelte@latest
12-
13-
# create a new project in my-app
14-
npm create svelte@latest my-app
15-
```
16-
17-
## Developing
18-
19-
Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server:
20-
21-
```bash
22-
npm run dev
23-
24-
# or start the server and open the app in a new browser tab
25-
npm run dev -- --open
26-
```
27-
28-
## Building
29-
30-
To create a production version of your app:
31-
32-
```bash
33-
npm run build
34-
```
35-
36-
You can preview the production build with `npm run preview`.
37-
38-
> To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment.
8+
1. `git clone https://github.com/exceptionless/Exceptionless.JavaScript`
9+
2. `cd Exceptionless.Javascript`
10+
3. `npm install`
11+
4. `cd example/svelte-kit`
12+
5. `npm run dev -- --open`

example/svelte-kit/src/hooks.js renamed to example/svelte-kit/src/hooks.client.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ Exceptionless.startup(c => {
55
c.serverUrl = "http://localhost:5000";
66
});
77

8-
/** @type {import('@sveltejs/kit').HandleError} */
9-
export async function handleError({ error, request }) {
8+
/** @type {import('@sveltejs/kit').HandleClientError} */
9+
export async function handleError({ error, event }) {
10+
console.log('client error handler');
1011
await Exceptionless.submitException(error);
1112
}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Exceptionless } from "@exceptionless/node";
2+
3+
Exceptionless.startup(c => {
4+
c.apiKey = "LhhP1C9gijpSKCslHHCvwdSIz298twx271n1l6xw";
5+
c.serverUrl = "http://localhost:5000";
6+
});
7+
8+
/** @type {import('@sveltejs/kit').HandleServerError} */
9+
export async function handleError({ error, event }) {
10+
console.log('server error handler');
11+
await Exceptionless.submitException(error);
12+
}
+80-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,82 @@
1-
<h1>Welcome to SvelteKit</h1>
2-
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
3-
41
<script>
5-
const badVariable = () => {
6-
return fakeVariable;
7-
}
8-
badVariable();
2+
import { Exceptionless } from "@exceptionless/browser";
3+
4+
let message = null;
5+
let errorInfo = null;
6+
7+
async function submitMessage() {
8+
await Exceptionless.submitLog("Hello, world!");
9+
errorInfo = null;
10+
message = "Hello, world!";
11+
};
12+
13+
async function tryCatchExample() {
14+
try {
15+
throw new Error("Caught in the try/catch");
16+
} catch (error) {
17+
message = null;
18+
errorInfo = error.message;
19+
await Exceptionless.submitException(error);
20+
}
21+
};
22+
23+
function unhandledExceptionExample() {
24+
throw new Error("Unhandled exception");
25+
};
926
</script>
27+
28+
<div class="App">
29+
<header class="App-header">
30+
<div class="container">
31+
<h1 class="App-title">Exceptionless Svelte Sample</h1>
32+
<div>
33+
<p>
34+
Throw an uncaught error and make sure Exceptionless tracks it.
35+
</p>
36+
<button on:click={unhandledExceptionExample}>
37+
Throw unhandled error
38+
</button>
39+
</div>
40+
<p>
41+
The following buttons simulated handled events outside the
42+
component.
43+
</p>
44+
<button on:click={submitMessage}>Submit Message</button>
45+
{#if message}
46+
<p>
47+
Message sent to Exceptionless:{" "}
48+
<code>{message}</code>
49+
</p>
50+
{/if}
51+
<button on:click={tryCatchExample}>Try/Catch Example</button>
52+
{#if errorInfo}
53+
<p>
54+
Error message sent to Exceptionless:{" "}
55+
<code>{errorInfo}</code>
56+
</p>
57+
{/if}
58+
</div>
59+
</header>
60+
</div>
61+
62+
<style>
63+
.App {
64+
text-align: center;
65+
}
66+
67+
.App-header {
68+
background-color: #282c34;
69+
min-height: 100vh;
70+
display: flex;
71+
flex-direction: column;
72+
align-items: center;
73+
justify-content: center;
74+
font-size: calc(10px + 2vmin);
75+
color: white;
76+
}
77+
78+
.container {
79+
max-width: 85%;
80+
margin: auto;
81+
}
82+
</style>

0 commit comments

Comments
 (0)