MCPcopy
hub / github.com/fastify/fastify / preParsingHookRunner

Function preParsingHookRunner

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

Source from the content-addressed store, hash-verified

323const preSerializationHookRunner = onSendHookRunner
324
325function preParsingHookRunner (functions, request, reply, cb) {
326 let i = 0
327
328 function next (err, newPayload) {
329 if (reply.sent) {
330 return
331 }
332
333 if (newPayload !== undefined) {
334 request[kRequestPayloadStream] = newPayload
335 }
336
337 if (err || i === functions.length) {
338 cb(err, request, reply)
339 return
340 }
341
342 let result
343 try {
344 result = functions[i++](request, reply, request[kRequestPayloadStream], next)
345 } catch (error) {
346 cb(error, request, reply)
347 return
348 }
349
350 if (result && typeof result.then === 'function') {
351 result.then(handleResolve, handleReject)
352 }
353 }
354
355 function handleResolve (newPayload) {
356 next(null, newPayload)
357 }
358
359 function handleReject (err) {
360 if (!err) {
361 err = new FST_ERR_SEND_UNDEFINED_ERR()
362 }
363
364 cb(err, request, reply)
365 }
366
367 next()
368}
369
370function onRequestAbortHookRunner (functions, request, cb) {
371 let i = 0

Callers 1

runPreParsingFunction · 0.85

Calls 1

nextFunction · 0.85

Tested by

no test coverage detected