Skip to content

Commit

Permalink
Throw error if fakeContext is used unexpectedly
Browse files Browse the repository at this point in the history
  • Loading branch information
legrego committed Apr 8, 2021
1 parent fcc1853 commit 2e0ac39
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/core/server/http/http_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,18 @@ export class HttpService
let notReadyServer: InternalNotReadyHttpServiceSetup | undefined;
if (notReadySetup) {
// We cannot use the real context container since the core services may not yet be ready
const fakeContext: RequestHandlerContextContainer = deps.context.createContextContainer();
const fakeContext: RequestHandlerContextContainer = new Proxy(
deps.context.createContextContainer(),
{
get: (target, property, receiver) => {
if (property === 'createHandler') {
return Reflect.get(target, property, receiver);
}
throw new Error(`Unexpected access from fake context: ${String(property)}`);
},
}
);

notReadyServer = {
registerRoutes: (path: string, registerCallback: (router: IRouter) => void) => {
const router = new Router(
Expand Down

0 comments on commit 2e0ac39

Please sign in to comment.