Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 1.27 KB

index.md

File metadata and controls

42 lines (32 loc) · 1.27 KB
type code title description order
page
false
Hook | Framework | Core
Hook events list
100

Hook Error

When an application or plugin's hook function returns a rejected promise, the event hook:onError is emitted.

Handlers attached to this event will receive the following arguments:

Arguments Type Description
pluginName
String
Application or plugin name
event
String
Original event to which the hook was attached
error
Error
Error object

::: info To prevent infinite loops, if a hook attached to the hook:onError event fails, it won't trigger any other events. :::

Example

Consider a plugin with the following hooks:

this.hooks = {
  // Each errored hook will trigger this method
  'hook:onError': (pluginName, event, error) => {
    this.context.accessors.error(`${pluginName} hook on ${event} failed: ${error.message}`)
  },

  // Each call to document:create will trigger this method, throwing an error
  'document:beforeCreate': async request => {
    throw new Error('The cake is a lie');
  }   
};