Skip to content

Commit bc10cb6

Browse files
committed
fix
1 parent 97cc708 commit bc10cb6

File tree

2 files changed

+31
-25
lines changed

2 files changed

+31
-25
lines changed
Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
import type {NextFunction, Request, Response} from '@gravity-ui/expresskit';
22
import {REQUEST_ID_PARAM_NAME} from '@gravity-ui/nodekit';
33

4+
import {onFail} from '../callbacks';
45
import {registry} from '../registry';
56
import type {DatalensGatewaySchemas} from '../types/gateway';
67

78
export function getTenantSettingsMiddleware() {
8-
return async function tenantSettingsMiddleware(
9-
req: Request,
10-
res: Response,
11-
next: NextFunction,
12-
) {
9+
async function resolveTenantSettings(req: Request, res: Response, next: NextFunction) {
1310
const {ctx} = req;
1411

15-
try {
16-
const requestId = req.ctx.get(REQUEST_ID_PARAM_NAME);
17-
const currentTenantId = 'common';
12+
const requestId = req.ctx.get(REQUEST_ID_PARAM_NAME);
13+
const currentTenantId = 'common';
1814

19-
const {gatewayApi} = registry.getGatewayApi<DatalensGatewaySchemas>();
20-
const {getAuthArgsUSPrivate} = registry.common.auth.getAll();
21-
const authArgsUSPrivate = getAuthArgsUSPrivate(req, res);
15+
const {gatewayApi} = registry.getGatewayApi<DatalensGatewaySchemas>();
16+
const {getAuthArgsUSPrivate} = registry.common.auth.getAll();
17+
const authArgsUSPrivate = getAuthArgsUSPrivate(req, res);
2218

23-
const tenantDetailsResponce = await gatewayApi.usPrivate._getTenantDetails({
24-
ctx,
25-
headers: req.headers,
26-
requestId: requestId ?? '',
27-
authArgs: authArgsUSPrivate,
28-
args: {tenantId: currentTenantId},
29-
});
30-
const resolvedTenant = tenantDetailsResponce.responseData;
31-
res.locals.tenantDefaultColorPaletteId = resolvedTenant.settings?.defaultColorPaletteId;
19+
const tenantDetailsResponce = await gatewayApi.usPrivate._getTenantDetails({
20+
ctx,
21+
headers: req.headers,
22+
requestId: requestId ?? '',
23+
authArgs: authArgsUSPrivate,
24+
args: {tenantId: currentTenantId},
25+
});
26+
const resolvedTenant = tenantDetailsResponce.responseData;
27+
res.locals.tenantDefaultColorPaletteId = resolvedTenant.settings?.defaultColorPaletteId;
3228

33-
next();
34-
} catch (error) {
35-
ctx.logError('TENANT_RESOLVED_FAILED', error);
29+
next();
30+
}
3631

37-
next(error);
38-
}
32+
return function resolveTenantSettingsMiddleware(
33+
req: Request,
34+
res: Response,
35+
next: NextFunction,
36+
) {
37+
resolveTenantSettings(req, res, next)
38+
.catch((error) => {
39+
req.ctx.logError('TENANT_RESOLVED_FAILED', error);
40+
onFail(req, res);
41+
})
42+
.catch((error) => next(error));
3943
};
4044
}

tests/docker-compose.e2e.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ services:
114114
environment:
115115
APP_MODE: full
116116
APP_ENV: production
117+
US_MASTER_TOKEN: ${US_MASTER_TOKEN:-us-master-token}
117118
APP_INSTALLATION: opensource
118119
AUTH_POLICY: disabled
119120
US_ENDPOINT: http://us:8080
@@ -140,6 +141,7 @@ services:
140141
environment:
141142
APP_MODE: full
142143
APP_ENV: production
144+
US_MASTER_TOKEN: ${US_MASTER_TOKEN:-us-master-token}
143145
APP_INSTALLATION: opensource
144146
AUTH_POLICY: disabled
145147
US_ENDPOINT: http://us:8080

0 commit comments

Comments
 (0)