Skip to content

Stop Event Processing

In some scenarios it might be required to stop further processing of an API event in a "before" event handler. For example, suppose a "beforeRegister" event handler performs user validation and must prevent default Backendless logic from executing. Backendless supports this scenario through a special return type. See the example below:

/**
* @param {Object} req The request object contains information about the request
* @param {Object} req.context The execution context contains an information about application, current user and event
* @param {Object} req.user 
*
* @returns {Object|Promise.<Object>|void} By returning a value you can stop further event propagation and return
*          a specific result to the caller
*/
Backendless.ServerCode.User.beforeRegister(function(req) {
  // your user validation logic goes here

  // return a special JS object with the "short" property set to true
  return { short: true }
});

By returning a JS object with the "short" property set to true, the code instructs Backendless to stop further processing of the event.