Skip to content

checkContext

utils
Source Code | Documentation

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.

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
ArgumentTypeDescription
contextH
typeHookType | HookType[] | null
methodsMethodName | MethodName[] | null
labelany

Released under the MIT License.