mirror of
https://github.com/logto-io/logto.git
synced 2025-03-17 22:31:28 -05:00
refactor(core): try to fix uncaught exception (#5982)
This commit is contained in:
parent
4d3b32f5f3
commit
123ecaec47
1 changed files with 14 additions and 5 deletions
|
@ -1,4 +1,5 @@
|
|||
import { adminTenantId, experience } from '@logto/schemas';
|
||||
import { ConsoleLog } from '@logto/shared';
|
||||
import type { MiddlewareType } from 'koa';
|
||||
import Koa from 'koa';
|
||||
import compose from 'koa-compose';
|
||||
|
@ -33,6 +34,8 @@ import Queries from './Queries.js';
|
|||
import type TenantContext from './TenantContext.js';
|
||||
import { getTenantDatabaseDsn } from './utils.js';
|
||||
|
||||
const consoleLog = new ConsoleLog('tenant');
|
||||
|
||||
/** Data for creating a tenant instance. */
|
||||
type CreateTenant = {
|
||||
/** The unique identifier of the tenant. */
|
||||
|
@ -45,12 +48,18 @@ type CreateTenant = {
|
|||
|
||||
export default class Tenant implements TenantContext {
|
||||
static async create({ id, redisCache, customDomain }: CreateTenant): Promise<Tenant> {
|
||||
// Treat the default database URL as the management URL
|
||||
const envSet = new EnvSet(id, await getTenantDatabaseDsn(id));
|
||||
// Custom endpoint is used for building OIDC issuer URL when the request is a custom domain
|
||||
await envSet.load(customDomain);
|
||||
// Try to avoid unexpected "triggerUncaughtException" by using try-catch block
|
||||
try {
|
||||
// Treat the default database URL as the management URL
|
||||
const envSet = new EnvSet(id, await getTenantDatabaseDsn(id));
|
||||
// Custom endpoint is used for building OIDC issuer URL when the request is a custom domain
|
||||
await envSet.load(customDomain);
|
||||
|
||||
return new Tenant(envSet, id, new WellKnownCache(id, redisCache));
|
||||
return new Tenant(envSet, id, new WellKnownCache(id, redisCache));
|
||||
} catch (error) {
|
||||
consoleLog.error('Failed to create tenant:', id, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
public readonly provider: Provider;
|
||||
|
|
Loading…
Add table
Reference in a new issue