Skip to content

Commit

Permalink
chore: improve logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy committed Jul 18, 2024
1 parent 638997d commit 30b9310
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions packages/vite/src/node/server/middlewares/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,23 @@ export function errorMiddleware(
<meta charset="UTF-8" />
<title>Error</title>
<script type="module">
const error = ${JSON.stringify(prepareError(err)).replace(
/</g,
'\\u003c',
)}
try {
const { ErrorOverlay } = await import('/@vite/client')
document.body.appendChild(new ErrorOverlay(${JSON.stringify(
prepareError(err),
).replace(/</g, '\\u003c')}))
document.body.appendChild(new ErrorOverlay(error))
} catch {
document.innerHTML = \`<h1>Internal Server Error</h1><h2>Error overlay failed to load</h2><pre>${err.stack?.replaceAll('<', '&lt;').replaceAll('$', '&dollar;')}</pre>\`
const h = (tag, text) => {
const el = document.createElement(tag)
el.textContent = text
return el
}
document.body.appendChild(h('h1', 'Internal Server Error'))
document.body.appendChild(h('h2', error.message))
document.body.appendChild(h('pre', error.stack))
document.body.appendChild(h('p', '(Error overlay failed to load)'))
}
</script>
</head>
Expand Down

0 comments on commit 30b9310

Please sign in to comment.