Skip to content

[http-server-js][Bug]: adding a global policy throws an error #9888

@benjlevesque

Description

@benjlevesque

Describe the bug

When using http-server-js with a custom global policy, an error is thrown.

const policy: Policy = async (ctx, next) => {
  next();
}
const router = createDemoServiceRouter({...}, { policies: [policy] });
// ...

this will always throw TypeError: Cannot read properties of undefined (reading 'catch')

Reproduction

Here is a repo with the reproduction of each case https://github.com/benjlevesque/repro-typespec-issues/blob/main/policy.test.ts

Resolution lead

The bug seems to be in the implementation of createPolicyChain, which does not return a Promise when at least one Policy is specified.
Adding async or returning Promise.resolve fixes the problem

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions