Skip to content

Commit

Permalink
FIXME error page
Browse files Browse the repository at this point in the history
  • Loading branch information
zmc committed Oct 3, 2024
1 parent 31d9d4a commit 14b90d4
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/pages/_error/+Page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { usePageContext } from 'vike-react/usePageContext'

export function Page() {
const pageContext = usePageContext()

let msg: string // Message shown to the user
const { abortReason, abortStatusCode } = pageContext
if (abortReason?.notAdmin) {
// Handle `throw render(403, { notAdmin: true })`
msg = "You cannot access this page because you aren't an administrator."
} else if (typeof abortReason === 'string') {
// Handle `throw render(abortStatusCode, `You cannot access ${someCustomMessage}`)`
msg = abortReason
} else if (abortStatusCode === 403) {
// Handle `throw render(403)`
msg = "You cannot access this page because you don't have enough privileges."
} else if (abortStatusCode === 401) {
// Handle `throw render(401)`
msg = "You cannot access this page because you aren't logged in. Please log in."
} else {
// Fallback error message
msg = pageContext.is404 ?
"This page doesn't exist." :
"Failed to fetch data; is teuthology-api reachable?"
}

console.log(pageContext)
return <p>{msg}</p>
}

// When using TypeScript you can define the type of `abortReason`
declare global {
namespace Vike {
interface PageContext {
abortReason?:
| string
| { notAdmin: true }
}
}
}

0 comments on commit 14b90d4

Please sign in to comment.