feathersjs / feathers

The API and real-time application framework
https://feathersjs.com
MIT License
15.04k stars 751 forks source link

Custom Method - Promise<void> not handles by ExternalResolver - error #3357

Closed elvince closed 8 months ago

elvince commented 10 months ago

Steps to reproduce

Hi,

Create a FeatherService with a custom method:

  async test(
    data: {}
    params: FlightMetadataParams,
  ) {
// do not nothing for this test
await setTimeout(5);
}

If you call this method, you will get an error on server side:

error: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Resolver.resolve (D:\workspaces\metaflight-flight-service\node_modules\@feathersjs\schema\src\resolver.ts:138:30)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async runResolvers (D:\workspaces\metaflight-flight-service\node_modules\@feathersjs\schema\src\hooks\resolve.ts:22:17)
    at async resolveAndGetDispatch (D:\workspaces\metaflight-flight-service\node_modules\@feathersjs\schema\src\hooks\resolve.ts:160:26)

The issue is coming out from the resolveExternal.

here is the resolver definition:

export const myExternalResolver = resolve<
  ServiceName,
  HookContext<ServiceNameService>
>({});

When looking at the code level, the resolver always expect an object so he can manipulate the property, but in case of custom method, we don't have any requirements in docs that that we must return an object (even empty).

Expected behavior

We should receive a 204 when the custom method return a promise.

Actual behavior

error: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at Resolver.resolve (D:\workspaces\metaflight-flight-service\node_modules\@feathersjs\schema\src\resolver.ts:138:30)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async runResolvers (D:\workspaces\metaflight-flight-service\node_modules\@feathersjs\schema\src\hooks\resolve.ts:22:17)
    at async resolveAndGetDispatch (D:\workspaces\metaflight-flight-service\node_modules\@feathersjs\schema\src\hooks\resolve.ts:160:26)

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working):

NodeJS version: 20.x

Operating System: win10

Module Loader: 5.0.11

elvince commented 8 months ago

Hi, Can I have a feedback on this? is it by design or something we can improve? Thanks,