MCPcopy
hub / github.com/fastify/fastify / handler

Function handler

test/serialize-response.test.js:74–106  ·  view source on GitHub ↗
(request, reply)

Source from the content-addressed store, hash-verified

72}
73
74const handler = (request, reply) => {
75 if (request.body.id === '400') {
76 return reply.status(400).send({
77 statusCode: 400,
78 error: 'Bad Request',
79 message: 'Custom message',
80 extra: 'This should not be in the response'
81 })
82 }
83
84 if (request.body.id === '404') {
85 return reply.status(404).send({
86 statusCode: 404,
87 error: 'Not Found',
88 message: 'Custom Not Found',
89 extra: 'This should not be in the response'
90 })
91 }
92
93 if (request.body.id === '500') {
94 reply.status(500).send({
95 statusCode: 500,
96 error: 'Internal Server Error',
97 message: 'Custom Internal Server Error',
98 extra: 'This should not be in the response'
99 })
100 }
101
102 reply.send({
103 id: request.body.id,
104 extra: 'This should not be in the response'
105 })
106}
107
108test('serialize the response for a Bad Request error, as defined on the schema', async t => {
109 t.plan(2)

Callers

nothing calls this directly

Calls 2

sendMethod · 0.80
statusMethod · 0.80

Tested by

no test coverage detected