MCPcopy
hub / github.com/fastify/fastify / preHandlerCallbackInner

Function preHandlerCallbackInner

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

Source from the content-addressed store, hash-verified

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