(err, request, reply, store)
| 153 | } |
| 154 | |
| 155 | function 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 | |
| 200 | module.exports = handleRequest |
| 201 | module.exports[Symbol.for('internals')] = { handler, preHandlerCallback } |
no test coverage detected