MCPcopy Create free account
hub / github.com/fastify/fastify / preHandlerCallbackInner

Function preHandlerCallbackInner

lib/handle-request.js:156–199  ·  view source on GitHub ↗
(err, request, reply, store)

Source from the content-addressed store, hash-verified

154}
155
156function preHandlerCallbackInner (err, request, reply, store) {
157 const context = request[kRouteContext]
158
159 try {
160 if (err != null) {
161 reply[kReplyIsError] = true
162 if (store) {
163 store.error = err
164 // Set status code before publishing so subscribers see the correct value
165 setErrorStatusCode(reply, err)
166 channels.error.publish(store)
167 }
168 reply.send(err)
169 return
170 }
171
172 let result
173
174 try {
175 result = context.handler(request, reply)
176 } catch (err) {
177 if (store) {
178 store.error = err
179 // Set status code before publishing so subscribers see the correct value
180 setErrorStatusCode(reply, err)
181 channels.error.publish(store)
182 }
183
184 reply[kReplyIsError] = true
185 reply.send(err)
186 return
187 }
188
189 if (result !== undefined) {
190 if (result !== null && typeof result.then === 'function') {
191 wrapThenable(result, reply, store)
192 } else {
193 reply.send(result)
194 }
195 }
196 } finally {
197 if (store) channels.end.publish(store)
198 }
199}
200
201module.exports = handleRequest
202module.exports[Symbol.for('internals')] = { handler, preHandlerCallback }

Callers 1

preHandlerCallbackFunction · 0.85

Calls 3

setErrorStatusCodeFunction · 0.85
wrapThenableFunction · 0.85
sendMethod · 0.80

Tested by

no test coverage detected