Skip to content

Commit b918ea7

Browse files
authored
chore: add url to logs on auth errors, move the message (#7154)
1 parent 699f445 commit b918ea7

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

packages/cubejs-api-gateway/src/gateway.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,11 +2146,6 @@ class ApiGateway {
21462146
req.securityContext = await checkAuthFn(auth, secret);
21472147
req.signedWithPlaygroundAuthSecret = Boolean(internalOptions?.isPlaygroundCheckAuth);
21482148
} catch (e) {
2149-
this.log({
2150-
type: (e as Error).message,
2151-
token: auth,
2152-
error: (e as Error).stack || (e as Error).toString()
2153-
}, <any>req);
21542149
if (this.enforceSecurityChecks) {
21552150
throw new CubejsHandlerError(403, 'Forbidden', 'Invalid token');
21562151
}
@@ -2272,6 +2267,13 @@ class ApiGateway {
22722267
}
22732268
} catch (e: unknown) {
22742269
if (e instanceof CubejsHandlerError) {
2270+
this.log({
2271+
type: (e as Error).message,
2272+
url: req.url,
2273+
token,
2274+
error: (e as Error).stack || (e as Error).toString()
2275+
}, <any>req);
2276+
22752277
res.status(e.status).json({ error: e.message });
22762278
} else if (e instanceof Error) {
22772279
this.log({

packages/cubejs-api-gateway/test/auth.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe('test authorization', () => {
129129
.set('Authorization', `Authorization: ${badToken}`)
130130
.expect(403);
131131

132-
expect(loggerMock.mock.calls.length).toEqual(3);
132+
expect(loggerMock.mock.calls.length).toEqual(1);
133133
expect(handlerMock.mock.calls.length).toEqual(2);
134134

135135
expectSecurityContext(handlerMock.mock.calls[0][0].context.securityContext);

0 commit comments

Comments
 (0)