Catch
function in meocord/decorator Since 4.1.0
Catch(
...errorTypes: (abstract new (...args: any[]) => unknown)[]
): (
target: new (...args: any[]) => ExceptionFilter<any>,
propertyKey?: string | symbol,
) => voidMarks a class as an exception filter for the given error types.
Use it on a class that implements ExceptionFilter, then apply the class with UseFilter or
@MeoCord({ filters }), to answer an error your own way. For a mistake the user can fix, throwing
UserError is often enough: the built-in fallback answers it with its message.
Where it runs
- Exception filters — where
@UseFilteror@MeoCord({ filters })applies it, around every stage and the handler
Parameters
| Name | Type | Description |
|---|---|---|
...errorTypes | (abstract new (...args: any[]) => unknown)[] | The error classes the filter handles. |
Returns
Returns a property decorator.
(
target: new (...args: any[]) => ExceptionFilter<any>,
propertyKey?: string | symbol,
) => voidExamples
@Catch(CooldownError)
export class WaitFilter implements ExceptionFilter<CooldownError> {
async catch(error: CooldownError, context: ExecutionContext) {
await context.response?.error(error, { message: `Slow down: try again ${time(error.retryAt, 'R')}.` })
}
}