Guides v2.x

Customize API Errors #

It is possible to customize the errors that we want to return in case of failure of an API request.

Kuzzle offers a set of standard errors corresponding to specific situations with customizable messages (e.g. NotFoundError,ForbiddenError, etc.)

Standard Errors #

Kuzzle exposes standard API errors classes.

The following constructors are available directly in the kuzzle package:

If a non-standard error is thrown, Kuzzle will instead return a standard PluginImplementationError error, embedding the thrown error.

Example: Throw a PreconditionError when an action parameter is missing

Copied to clipboard!
import { Backend, PreconditionError } from 'kuzzle';

app.controller.register('greeting', {
  actions: {
    sayHello: {
      handler: async request => {
        if ( === undefined) {
          throw new PreconditionError('Missing "name" argument.');

        return `Hello, ${}`;