File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments