N
Nuxt7mo ago
Cry0nicS

Basic error page with Typescript and NuxtError

I'm trying to create a basic error.vue The main issue is that I can't seem to find a way to set a default statusCode.
<script setup lang="ts">
import type {NuxtError} from "#app";

interface DefaultError {
statusCode: number;
message: string;
}

const {error} = withDefaults(
defineProps<{
error?: NuxtError<DefaultError>;
}>(),
{
error: {
statusCode: 500,
message: "An error occurred"
}
}
);

const handleError = () => clearError({ redirect: '/' })
</script>
<script setup lang="ts">
import type {NuxtError} from "#app";

interface DefaultError {
statusCode: number;
message: string;
}

const {error} = withDefaults(
defineProps<{
error?: NuxtError<DefaultError>;
}>(),
{
error: {
statusCode: 500,
message: "An error occurred"
}
}
);

const handleError = () => clearError({ redirect: '/' })
</script>
Keeps throwing Vue: Object literal may only specify known properties, and statusCode does not exist in type What's a good way to handle this. so that in the template I can do error.statusCode and error.message ?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server