Skip to content

How to crash server from error handler? #371

@sergejostir

Description

@sergejostir

💬 Question here

There seems to be no way to crash the server from the error handler as it will simply catch the error and try to send it as a response. I would like to respond to the request that an error occured and then crash the server because it might be in an undefined state.

const fastify = require('fastify').default;

const f = fastify({
  logger: true,
});

f.setErrorHandler((error, request, response) => {
  // The expected errors will be handled here, but unexpected ones should eventually result in a crash.

  response.send({ error: true });

  throw new Error('should crash');
});

f.get('/test', () => {
  const p = null;

  return p.oops;
});

f.listen(3000, '0.0.0.0');

My goal is to crash the server for any error that I wasn't expecting. Those that I did will be handled gracefully.

Your Environment

  • node version: 14
  • fastify version: 3.7.0
  • os: Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions