Skip to Content
nyx logonyx guide

Error Handler

See in:
BasicErrorHandlerGitHub
EventSubscriberErrorHandlerGitHub
ErrorHandlerGitHub
Reading time:2 min read

The EventSubscriberErrorHandler handles errors thrown while checking middlewares or executing event subscribers.

It's inside the EventDispatcher object, and will be used by it.

When to override

✅ Override if you want to...❌ Don't override if you want to...
Resolve error consumers with custom logic.Add/remove subscribers from buses. That's done with EventBus#subscribe() and EventBus#unsubscribe().
Change fallback behavior for uncaught errors (logging, telemetry, alerting).Change middleware order. Use the dispatcher middleware list for that.
Route specific error classes to specialized consumers.Replace dispatch flow entirely. If you only want custom error handling, replacing this dependency is enough.

Overriding

Creation

Create a custom error handler by either:

  • Extending BasicErrorHandler<AnyEventSubscriber, EventDispatchArgs> (recommended, less work).
  • Implementing EventSubscriberErrorHandler.
import { , type , type  } from '@nyx-discord/djs';

class  extends <, > {}

Registration

Inject it directly when creating the dispatcher:

import {  } from '@nyx-discord/djs';

const  = .({
  : {
    : .(),
  },
});

.();

Using the Bot's logger

To use the bot logger as fallback, create a handler with createWithFallbackLogger and inject it:

import {
  ,
  ,
  ,
  type ,
  type ,
  type ,
} from '@nyx-discord/djs';

type  = {
  : [string];
};

declare const : <>;

const  = .<, >(
  (, , []) => .(),
);

const  = .({
  : {
    ,
  },
});

.();
Edit on GitHub

Last updated on

On this page