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:
parent
2a642f4e21
commit
38ceae7853
2 changed files with 23 additions and 5 deletions
|
@ -62,4 +62,18 @@ describe('koaLogSession', () => {
|
||||||
await expect(koaLogSession(new Provider(''))(ctx, next)).resolves.not.toThrow();
|
await expect(koaLogSession(new Provider(''))(ctx, next)).resolves.not.toThrow();
|
||||||
expect(next).toHaveBeenCalled();
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -9,10 +9,14 @@ export default function koaLogSession<StateT, ContextT extends WithLogContext, R
|
||||||
return async (ctx, next) => {
|
return async (ctx, next) => {
|
||||||
await next();
|
await next();
|
||||||
|
|
||||||
|
try {
|
||||||
const {
|
const {
|
||||||
jti,
|
jti,
|
||||||
params: { client_id },
|
params: { client_id },
|
||||||
} = await provider.interactionDetails(ctx.req, ctx.res);
|
} = await provider.interactionDetails(ctx.req, ctx.res);
|
||||||
ctx.addLogContext({ sessionId: jti, applicationId: String(client_id) });
|
ctx.addLogContext({ sessionId: jti, applicationId: String(client_id) });
|
||||||
|
} catch (error: unknown) {
|
||||||
|
console.error(`"${ctx.url}" failed to get oidc provider interaction`, error);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue