Most extensions to Grind should be done via Providers, however there are several core classes that are created immediately upon instantiating Grind that need to be treated differently.

For these classes, you can pass in an object when creating an instance of Grind in app/Boostrap.js:

import 'App/Errors/ErrorHandler'
const app = new Grind({
  errorHandlerClass: ErrorHandler

Grind will now use the provided ErrorHandler class instead of the default one it ships with.

Here’s a list of available overrides:

Class Name Constructor Key Reference
Router routerClass Router.js
ErrorHandler errorHandlerClass ErrorHandler.js
Config configClass Config.js
UrlGenerator urlGeneratorClass UrlGenerator.js
Paths pathsClass Paths.js

grind-framework exports all of the above classes for you to subclass and extend.

Here’s an example overriding the ErrorHandler class to report errors to a collector API:

import { ErrorHandler as BaseErrorHandler } from 'grind-framework'
import 'request' from 'request-promise-native'
export class ErrorHandler extends BaseErrorHandler {
  report(req, res, err, info) {
    return request('https://host/report', {
      form: {
        info: info,
        stack: err.stack