Skip to content

Commit b09dea0

Browse files
committed
feat: add basic form error handling
1 parent 2cd3c8d commit b09dea0

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

app/app.vue

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script setup lang="ts">
22
const runs = ref([]);
3+
const error = ref(null);
34
45
const handleRequestFormSubmit = async ({ url }): void => {
56
if (!url.startsWith("http")) {
@@ -19,9 +20,13 @@ const handleRequestFormSubmit = async ({ url }): void => {
1920
cacheHeaders: getCacheHeaders(responseBody.headers),
2021
durationInMs: responseBody.durationInMs,
2122
});
23+
24+
error.value = null;
2225
} catch (err) {
23-
// TODO(serhalp) Proper error handling. ErrorBoundary?
24-
console.error("Error fetching URL", err);
26+
error.value =
27+
err?.data?.message ??
28+
err?.toString?.() ??
29+
new Error(`Fetch error: ${err}`);
2530
return;
2631
}
2732
};
@@ -45,6 +50,10 @@ const handleClickClear = (): void => {
4550
<main>
4651
<RequestForm @submit="handleRequestFormSubmit" />
4752

53+
<div v-if="error" class="error">
54+
{{ error }}
55+
</div>
56+
4857
<div class="flex-btwn run-panels">
4958
<RunPanel v-for="run in runs" v-bind="run" />
5059
</div>
@@ -76,6 +85,10 @@ main {
7685
padding-bottom: 3em;
7786
}
7887
88+
.error {
89+
color: var(--red-400);
90+
}
91+
7992
.run-panels {
8093
flex-wrap: wrap;
8194
align-items: stretch;

0 commit comments

Comments
 (0)