throwIf
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>| Argument | Type | Description |
|---|---|---|
| predicate | PredicateFn | |
| options | ThrowIfOptions |
| type | methods | multi |
|---|---|---|
| before, after, around | create, update, patch | yes |
