mirror of
https://github.com/logto-io/logto.git
synced 2025-03-24 22:41: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 { adminTenantId, experience } from '@logto/schemas';
|
||||||
|
import { ConsoleLog } from '@logto/shared';
|
||||||
import type { MiddlewareType } from 'koa';
|
import type { MiddlewareType } from 'koa';
|
||||||
import Koa from 'koa';
|
import Koa from 'koa';
|
||||||
import compose from 'koa-compose';
|
import compose from 'koa-compose';
|
||||||
|
@ -33,6 +34,8 @@ import Queries from './Queries.js';
|
||||||
import type TenantContext from './TenantContext.js';
|
import type TenantContext from './TenantContext.js';
|
||||||
import { getTenantDatabaseDsn } from './utils.js';
|
import { getTenantDatabaseDsn } from './utils.js';
|
||||||
|
|
||||||
|
const consoleLog = new ConsoleLog('tenant');
|
||||||
|
|
||||||
/** Data for creating a tenant instance. */
|
/** Data for creating a tenant instance. */
|
||||||
type CreateTenant = {
|
type CreateTenant = {
|
||||||
/** The unique identifier of the tenant. */
|
/** The unique identifier of the tenant. */
|
||||||
|
@ -45,12 +48,18 @@ type CreateTenant = {
|
||||||
|
|
||||||
export default class Tenant implements TenantContext {
|
export default class Tenant implements TenantContext {
|
||||||
static async create({ id, redisCache, customDomain }: CreateTenant): Promise<Tenant> {
|
static async create({ id, redisCache, customDomain }: CreateTenant): Promise<Tenant> {
|
||||||
// Treat the default database URL as the management URL
|
// Try to avoid unexpected "triggerUncaughtException" by using try-catch block
|
||||||
const envSet = new EnvSet(id, await getTenantDatabaseDsn(id));
|
try {
|
||||||
// Custom endpoint is used for building OIDC issuer URL when the request is a custom domain
|
// Treat the default database URL as the management URL
|
||||||
await envSet.load(customDomain);
|
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;
|
public readonly provider: Provider;
|
||||||
|
|
Loading…
Add table
Reference in a new issue