Skip to Content
nyx logonyx guide

Error Handler

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

The ScheduleErrorHandler handles errors thrown while checking middlewares or executing schedule ticks.

It's inside the ScheduleExecutor 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 or remove middlewares. That's done with the executor's middleware list.
Change fallback behavior for uncaught errors, such as logging or telemetry.Change when schedules run. That's done with ScheduleExecutionScheduler and ScheduleJobAdapter.
Route specific error classes to specialized consumers.Replace the 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<Schedule, ScheduleTickArgs> (recommended, less work).
  • Implementing ScheduleErrorHandler.
import { , type Schedule, type  } from '@nyx-discord/djs';

class  extends <Schedule, > {}

Registration

Inject it directly when creating the executor, then set that executor to the ScheduleManager:

import type {  } from '@nyx-discord/djs';
declare const : ;

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

const  = new (
  .(),
  ,
);

.().();

Using the Bot's logger

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

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

declare const : ;

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

const  = new (
  .(),
  ,
);
Edit on GitHub

Last updated on

On this page