question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to override custom error handler

See original GitHub issue

I like the request methods this plugin adds, but how would like to handle the errors myself. How do I override the custom error handler? I’ve tried to add it after and before registering this plugin, but it never gets called;

fastify.setErrorHandler(function (error, request, reply) {
  // Never called here...
})

fastify.register(require('fastify-sensible'))

fastify.setErrorHandler(function (error, request, reply) {
  // Never called here...
})

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
delvedorcommented, Apr 6, 2018

Hi! The plugins are registered asynchronously, while the custom error handler is not.

This should fix your issue 😃

fastify
  .register(require('fastify-sensible'))
  .after(() => {
    fastify.setErrorHandler(function (error, request, reply) {
      reply.send(error)
    })
  })
Read more comments on GitHub >

github_iconTop Results From Across the Web

Customize error handler - Optimizely
Here is a code example where an error handler from the SDK is used. If the error handler is not overridden, a no-op...
Read more >
Angular override global ErrorHandler - Stack Overflow
We divide between the errors and then handle them with a service. handleError(error: any): void { const errorService = this.injector.
Read more >
Custom Error Handling | Advanced Topics | Flow - Vaadin
In order to do so, first create your custom ErrorHandler class, then use that class to override the default error handler via VaadinSession.getCurrent()....
Read more >
Custom Error Message Handling for REST API - Baeldung
Note that we are overriding a base method out of the ResponseEntityExceptionHandler and providing our own custom implementation.
Read more >
Get Started with Custom Error Handling in Spring Boot (Java)
Learn how to implement custom error handling logic in Spring Boot. You will see two approaches based on the @ControllerAdvice annotation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found