hooks icon indicating copy to clipboard operation
hooks copied to clipboard

Custom service methods missing

Open EmileSpecs opened this issue 11 months ago • 0 comments

For more context see: https://github.com/feathersjs/feathers/issues/3576

When a custom service method is added it does not exist as part of the obj passed to objectHooks function.

The result is that an error is thrown:

throw new Error(`Can not apply hooks. '${method}' is not a function...`);

I have a custom service method: async change(data: any, params?: Params): Promise<any> {}

When logging the obj provided in objectHooks that method is not present:

cs {
  update:
   { [Function: update]
     original: [Function: update],
     Context: [class ContextClass extends BaseHookContext],
     createContext: [Function: createContext],
     [Symbol(@feathersjs/hooks)]:
      FeathersHookManager {
        _parent: null,
        _params: [Array],
        _middleware: [],
        _props: [Object],
        _defaults: undefined,
        app: [Feathers],
        method: 'update' } },
  find:
   { [Function: find]
     original: [Function: find],
     Context: [class ContextClass extends BaseHookContext],
     createContext: [Function: createContext],
     [Symbol(@feathersjs/hooks)]:
      FeathersHookManager {
        _parent: null,
        _params: [Array],
        _middleware: [],
        _props: [Object],
        _defaults: undefined,
        app: [Feathers],
        method: 'find' } },
  get:
   { [Function: get]
     original: [Function: get],
     Context: [class ContextClass extends BaseHookContext],
     createContext: [Function: createContext],
     [Symbol(@feathersjs/hooks)]:
      FeathersHookManager {
        _parent: null,
        _params: [Array],
        _middleware: [],
        _props: [Object],
        _defaults: undefined,
        app: [Feathers],
        method: 'get' } },
  create:
   { [Function: create]
     original: [Function: create],
     Context: [class ContextClass extends BaseHookContext],
     createContext: [Function: createContext],
     [Symbol(@feathersjs/hooks)]:
      FeathersHookManager {
        _parent: null,
        _params: [Array],
        _middleware: [],
        _props: [Object],
        _defaults: undefined,
        app: [Feathers],
        method: 'create' } },
  patch:
   { [Function: patch]
     original: [Function: patch],
     Context: [class ContextClass extends BaseHookContext],
     createContext: [Function: createContext],
     [Symbol(@feathersjs/hooks)]:
      FeathersHookManager {
        _parent: null,
        _params: [Array],
        _middleware: [],
        _props: [Object],
        _defaults: undefined,
        app: [Feathers],
        method: 'patch' } },
  remove:
   { [Function: remove]
     original: [Function: remove],
     Context: [class ContextClass extends BaseHookContext],
     createContext: [Function: createContext],
     [Symbol(@feathersjs/hooks)]:
      FeathersHookManager {
        _parent: null,
        _params: [Array],
        _middleware: [],
        _props: [Object],
        _defaults: undefined,
        app: [Feathers],
        method: 'remove' } } }

I don't know if the issue is in the feathers/hooks repo/package or if the issue is upstream in feathers.

I didn't have this issue in feathers 5.0.24 (if I remember correctly).

@daffl hope this gives you something more to work with.

EmileSpecs avatar May 21 '25 08:05 EmileSpecs