Skip to content

throwIf

Source Code | Documentation

Throw an error if the predicate function returns true.

This hook is useful for validating conditions before proceeding with the request.

ts
  import { 
throwIf
} from 'feathers-utils/hooks';

Type declaration

ts
export type ThrowIfOptions = {
  /**
   * Customize the error that is thrown if the predicate returns true.
   *
   * If not provided, throws a `BadRequest` error with 'Invalid operation'.
   */
  error?: (context: HookContext) => FeathersError
}
/**
 * Throw an error if the predicate function returns true.
 *
 * This hook is useful for validating conditions before proceeding with the request.
 *
 * @see https://utils.feathersjs.com/hooks/throw-if.html
 */
export declare const throwIf: <H extends HookContext = HookContext>(
  predicate: PredicateFn,
  options?: ThrowIfOptions,
) => (context: H, next?: NextFunction) => Promise<any>
ArgumentTypeDescription
predicatePredicateFn
optionsThrowIfOptions
typemethodsmulti
before, after, aroundcreate, update, patchyes

Released under the MIT License.