Fastify "Promise may not be fulfilled with 'undefined' when statusCode is not 204"

Viewed 2496

I am learning Fastify and created a post route. My code for the same is as below:

const route = async (fastify) => {
  // get route api/v1/test/
  fastify.get('/', async (request, reply) => {});

  // post route api/v1/test/
  fastify.post('/', async (request, reply) => {
    fastify.log.info(`request with body ${request}`);
    const { title } = request.body;

    const id = await fastify.db.one(
      'INSERT INTO test(title) VALUES($1) RETURNING id',
      [title]
    );

    reply.code(201).send(id);
  });
};

However, I'm repeatedly facing the error:

ERROR (516 on build-fastify-env): Promise may not be fulfilled with 'undefined' when statusCode is not 204
    reqId: "req-1"
    err: {
      "type": "FastifyError",
      "message": "Promise may not be fulfilled with 'undefined' when statusCode is not 204",
      "stack":
          FastifyError: Promise may not be fulfilled with 'undefined' when statusCode is not 204
              at /code/node_modules/fastify/lib/wrapThenable.js:30:30
      "name": "FastifyError",
      "code": "FST_ERR_PROMISE_NOT_FULFILLED",
      "statusCode": 500
    }

Can anyone help me with where I might be going wrong?

0 Answers
Related