Skip to content

Commit 08b10f2

Browse files
committed
⭐ feat: throw error when car does not exist
1 parent bd9b2fc commit 08b10f2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

error.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup>
22
const error = useError();
33
const handleGoBack = () => {
4-
navigateTo("/");
4+
clearError({ redirect: "/" });
55
};
66
</script>
77

pages/car/[name]-[id].vue

+7-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ const car = computed(() => {
77
const carId = parseInt(route.params.id);
88
return cars.find((car) => car.id === carId);
99
});
10-
10+
console.log(car);
11+
if (!car.value) {
12+
throw createError({
13+
statusCode: 404,
14+
message: `Car with id ${route.params.id} does not exist`,
15+
});
16+
}
1117
useHead({ title: toTitleCase(route.params.name) });
1218
1319
definePageMeta({

0 commit comments

Comments
 (0)