Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dev-server): use toString() for the error message #47

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/real-poets-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hono/vite-dev-server': patch
---

fix: use `toString()` for the error message
9 changes: 4 additions & 5 deletions packages/dev-server/src/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ export function devServer(options?: DevServerOptions): Plugin {
* If the response is not instance of `Response`, it returns simple HTML with error messages.
*/
if (!(response instanceof Response)) {
const message = 'The response is not an instance of "Response", but: ' + response
// @ts-expect-error response object must have `toString()`
const message = `The response is not an instance of "Response", but: ${response.toString()}`
console.error(message)
response = createErrorResponse(message)
}
Expand Down Expand Up @@ -127,11 +128,9 @@ function escapeHtml(str: string): string {
.replace(/'/g, ''')
}

function createErrorResponse(body: BodyInit) {
function createErrorResponse(body: string) {
return new Response(
`<html><body><pre style="white-space:pre-wrap;">${escapeHtml(
body.toString()
)}</pre></body></html>`,
`<html><body><pre style="white-space:pre-wrap;">${escapeHtml(body)}</pre></body></html>`,
{
status: 500,
headers: {
Expand Down