MCPcopy
hub / github.com/fastify/fastify / onSendHookRunner

Function onSendHookRunner

lib/hooks.js:278–321  ·  view source on GitHub ↗
(functions, request, reply, payload, cb)

Source from the content-addressed store, hash-verified

276const onRequestHookRunner = hookRunnerGenerator(hookIterator)
277
278function onSendHookRunner (functions, request, reply, payload, cb) {
279 let i = 0
280
281 function next (err, newPayload) {
282 if (err) {
283 cb(err, request, reply, payload)
284 return
285 }
286
287 if (newPayload !== undefined) {
288 payload = newPayload
289 }
290
291 if (i === functions.length) {
292 cb(null, request, reply, payload)
293 return
294 }
295
296 let result
297 try {
298 result = functions[i++](request, reply, payload, next)
299 } catch (error) {
300 cb(error, request, reply)
301 return
302 }
303 if (result && typeof result.then === 'function') {
304 result.then(handleResolve, handleReject)
305 }
306 }
307
308 function handleResolve (newPayload) {
309 next(null, newPayload)
310 }
311
312 function handleReject (err) {
313 if (!err) {
314 err = new FST_ERR_SEND_UNDEFINED_ERR()
315 }
316
317 cb(err, request, reply, payload)
318 }
319
320 next()
321}
322
323const preSerializationHookRunner = onSendHookRunner
324

Callers 3

onSendHookFunction · 0.85
onErrorHookFunction · 0.85

Calls 1

nextFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…