Skip to content

Commit

Permalink
fix(Microservice): enhance logging in error cases
Browse files Browse the repository at this point in the history
  • Loading branch information
reey committed Mar 21, 2024
1 parent d7d0960 commit 9357174
Showing 1 changed file with 59 additions and 16 deletions.
75 changes: 59 additions & 16 deletions backend/src/connection-details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,50 @@ export class ConnectionDetails {
) {}

async extractDetails() {
this.getConnectionDetailsFromParams(this.req);
try {
this.getConnectionDetailsFromParams(this.req);
} catch (e) {
this.logger.error(
`Failed to get connection details from request params.`,
{
errorObj: e,
}
);
throw e;
}

this.isWebsocket = !!this.req.headers.upgrade;
this.queryParamsString = ConnectionDetails.getQueryParamsFromHeaders(
this.req.headers
);
this.originalHeaders = Object.assign({}, this.req.headers);
try {
this.queryParamsString = ConnectionDetails.getQueryParamsFromHeaders(
this.req.headers
);
} catch (e) {
this.logger.error(`Failed to generate query params from headers.`, {
errorObj: e,
});
throw e;
}

const { userId, tenantId, domain } = this.getUserAndTenantFromRequest(
this.req
);
this.originalHeaders = Object.assign({}, this.req.headers);

this.user = userId;
this.tenant = tenantId;
this.domain = domain;
try {
const { userId, tenantId, domain } = this.getUserAndTenantFromRequest(
this.req
);
this.user = userId;
this.tenant = tenantId;
this.domain = domain;
} catch (e) {
this.logger.error(`Failed to extract user and tenant out of request.`, {
errorObj: e,
});
throw e;
}

this.client = await this.getTenantDetailsClient(this.req.headers, domain);
this.client = await this.getTenantDetailsClient(
this.req.headers,
this.domain
);

if (this.logger.isDebugEnabled()) {
this.rcaConfig = await this.getRCAConfig();
Expand Down Expand Up @@ -85,6 +113,7 @@ export class ConnectionDetails {
}
}
if (!bearerToken) {
this.logger.debug("No token found to extract user or tenant from.");
return undefined;
}

Expand Down Expand Up @@ -119,10 +148,20 @@ export class ConnectionDetails {
if (domainFromCache) {
domain = domainFromCache;
} else {
const { data: currentTenant } = await initialClient.tenant.current();

domain = currentTenant.domainName;
domainCache.set(this.tenant, domain);
try {
const { data: currentTenant } = await initialClient.tenant.current();

domain = currentTenant.domainName;
this.logger.debug(`Retrieved domain name of current tenant`, {
domain,
});
domainCache.set(this.tenant, domain);
} catch (e) {
this.logger.error(`Failed to retrieve current tenant.`, {
errorObj: e,
});
throw e;
}
}
}

Expand Down Expand Up @@ -172,6 +211,10 @@ export class ConnectionDetails {
const { cloudProxyDeviceId, cloudProxyConfigId } = req.params;
this.cloudProxyConfigId = cloudProxyConfigId;
this.cloudProxyDeviceId = cloudProxyDeviceId;
this.logger.debug(`Extracted connection details from request params`, {
cloudProxyConfigId,
cloudProxyDeviceId,
});
}

private async getRCAConfig() {
Expand Down

0 comments on commit 9357174

Please sign in to comment.