Skip to content

Commit d7828f7

Browse files
committed
added error page
1 parent 515e495 commit d7828f7

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pages/_error/+Page.client.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// /pages/_error/+Page.ts
2+
3+
import { h } from '@macrostrat/map-interface'
4+
import { usePageContext } from 'vike-react/usePageContext'
5+
6+
export function Page() {
7+
const pageContext = usePageContext()
8+
9+
let msg: string // Message shown to the user
10+
const { abortReason, abortStatusCode } = pageContext
11+
if (abortReason?.notAdmin) {
12+
// Handle `throw render(403, { notAdmin: true })`
13+
msg = "You cannot access this page because you aren't an administrator."
14+
} else if (typeof abortReason === 'string') {
15+
// Handle `throw render(abortStatusCode, `You cannot access ${someCustomMessage}`)`
16+
msg = abortReason
17+
} else if (abortStatusCode === 403) {
18+
// Handle `throw render(403)`
19+
msg = "You cannot access this page because you don't have enough privileges."
20+
} else if (abortStatusCode === 401) {
21+
// Handle `throw render(401)`
22+
msg = "You cannot access this page because you aren't logged in. Please log in."
23+
} else {
24+
// Fallback error message
25+
msg = pageContext.is404 ?
26+
"This page doesn't exist." :
27+
"Something went wrong. Try again (later)."
28+
}
29+
30+
return h('h1', msg)
31+
}

0 commit comments

Comments
 (0)