(functions, request, reply, payload, cb)
| 276 | const onRequestHookRunner = hookRunnerGenerator(hookIterator) |
| 277 | |
| 278 | function 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 | |
| 323 | const preSerializationHookRunner = onSendHookRunner |
| 324 |
no test coverage detected
searching dependent graphs…