Skip to content

Commit 4f50527

Browse files
authored
fix: Refactor promise check for response handling (#277)
* Refactor promise check for response handling I got an error because `instanceof` wouldn't recognize `res` as a `Promise`. Might be related to my usage of `tsx`, idk. Anyway, if I change to check for a `then` method, everything works again. * Check for 'then' property before calling it * Refactor promise check in response handling
1 parent cf75f9d commit 4f50527

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/listener.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,15 @@ const responseViaCache = async (
9898
;(outgoing as OutgoingHasOutgoingEnded)[outgoingEnded]?.()
9999
}
100100

101+
const isPromise = (res: Response | Promise<Response>): res is Promise<Response> =>
102+
typeof (res as Promise<Response>).then === 'function'
103+
101104
const responseViaResponseObject = async (
102105
res: Response | Promise<Response>,
103106
outgoing: ServerResponse | Http2ServerResponse,
104107
options: { errorHandler?: CustomErrorHandler } = {}
105108
) => {
106-
if (res instanceof Promise) {
109+
if (isPromise(res)) {
107110
if (options.errorHandler) {
108111
try {
109112
res = await res

0 commit comments

Comments
 (0)