checkContext
utils
Source Code | DocumentationValidates that the hook context matches the expected type(s) and method(s). Throws an error if the context is invalid, preventing hooks from running in unsupported configurations. Typically used internally by other hooks.
ts
import { checkContext } from 'feathers-utils/utils';Example
ts
import { checkContext } from 'feathers-utils/utils'
const myHook = (context) => {
checkContext(context, ['before', 'around'], ['create', 'patch'], 'myHook')
// ... hook logic
}Type declaration
Show Type Declarations
ts
/**
* Validates that the hook context matches the expected type(s) and method(s).
* Throws an error if the context is invalid, preventing hooks from running in
* unsupported configurations. Typically used internally by other hooks.
*
* @example
* ```ts
*
*
* const myHook = (context) => {
* checkContext(context, ['before', 'around'], ['create', 'patch'], 'myHook')
* // ... hook logic
* }
* ```
*
* @see https://utils.feathersjs.com/utils/check-context.html
*/
export declare function checkContext<H extends HookContext = HookContext>(
context: H,
type?: HookType | HookType[] | null,
methods?: MethodName | MethodName[] | null,
label?: string,
): void| Argument | Type | Description |
|---|---|---|
| context | H | |
| type | HookType | HookType[] | null | |
| methods | MethodName | MethodName[] | null | |
| label | any |
