WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@houssems
Copy link

@houssems houssems commented Apr 5, 2025

Hi,

I'm working in Angular 19 SSR integration with Hono. While investigating a server crash on the loading of static files, I discovered that it didn't wait for the res object to get resolved. So status attribute doesn't exist in Res object. The issue is from instanceof Promise.

RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined at ServerResponse.writeHead (node:_http_server:351:11) at Hn (/dist/server/server.mjs:89:11) at Server.<anonymous> (/dist/server/server.mjs:91:554) at Server.emit (node:events:519:28) at parserOnIncoming (node:_http_server:1141:12) at HTTPParser.parserOnHeadersComplete (node:_http_common:118:17) { code: 'ERR_HTTP_INVALID_STATUS_CODE' }

@houssems
Copy link
Author

houssems commented Apr 8, 2025

@yusukebe
Would you please review this?

@usualoma
Copy link
Member

usualoma commented Apr 9, 2025

Hi @houssems. Thank you for creating a pull request!

Should we accept thenable?

When the following code was executed in Deno and "wrangler," a message was displayed. Bun caused an error.

import { Hono } from 'hono'

const app = new Hono()

app.get('/', () => {
  const res = {
    then(resolve) {
      setTimeout(() => {
        resolve(new Response('Hello from thenable!'))
      }, 1000);
    }
  }
  return res as Promise<Response>
})

export default app

As the type indicates, Hono is originally expecting an instance of "Promise", but I think it's okay to accept a thenable even if it's not an instance of "Promise".

res != null

Since it has already been guaranteed that res is not null or undefined using the following code before this point, I would like to omit res != null and prioritize performance.

if (cacheKey in res) {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants