0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-24 22:05:56 -05:00

fix(core): catch interaction not found error (#827)

This commit is contained in:
IceHe.xyz 2022-05-15 13:20:07 +08:00 committed by GitHub
parent 2a642f4e21
commit 38ceae7853
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 5 deletions

View file

@ -62,4 +62,18 @@ describe('koaLogSession', () => {
await expect(koaLogSession(new Provider(''))(ctx, next)).resolves.not.toThrow();
expect(next).toHaveBeenCalled();
});
it('should not throw when interactionDetails throw error', async () => {
const ctx: WithLogContext<ReturnType<typeof createContextWithRouteParameters>> = {
...createContextWithRouteParameters(),
addLogContext,
log,
};
interactionDetails.mockImplementationOnce(() => {
throw new Error('message');
});
await expect(koaLogSession(new Provider(''))(ctx, next)).resolves.not.toThrow();
});
});

View file

@ -9,10 +9,14 @@ export default function koaLogSession<StateT, ContextT extends WithLogContext, R
return async (ctx, next) => {
await next();
try {
const {
jti,
params: { client_id },
} = await provider.interactionDetails(ctx.req, ctx.res);
ctx.addLogContext({ sessionId: jti, applicationId: String(client_id) });
} catch (error: unknown) {
console.error(`"${ctx.url}" failed to get oidc provider interaction`, error);
}
};
}