Skip to content

Commit

Permalink
Pass arguments to fromRequest wrapped function
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie committed Mar 2, 2022
1 parent e31a2ec commit 9d2924d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/zap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ function isReadableStream(val: unknown): val is Readable {
export function fromRequest<Fn extends (req: ServerRequest, ...rest: any[]) => any>(fn: Fn): Fn {
const cache = new WeakMap<ServerRequest, any>()
const errorCache = new WeakMap<ServerRequest, any>()
const cachedFn = (req: ServerRequest) => {
const cachedFn = (req: ServerRequest, ...rest: any[]) => {
if (errorCache.has(req)) throw errorCache.get(req)
if (cache.has(req)) return cache.get(req)
try {
const value = fn(req)
const value = fn(req, ...rest)
cache.set(req, value)
return value
} catch (error) {
Expand Down

0 comments on commit 9d2924d

Please sign in to comment.