mirror of
https://github.com/logto-io/logto.git
synced 2024-12-16 20:26:19 -05:00
fix(core): prevent uncaught promise rejection (#6009)
* fix(core): prevent uncaught promise rejection prevent uncaught promise rejection crashing the app * refactor(core): remove inline await remove inline await statement * chore(core): update comment update comment
This commit is contained in:
parent
136320584f
commit
930f23e363
2 changed files with 18 additions and 1 deletions
|
@ -33,6 +33,22 @@ try {
|
|||
SystemContext.shared.loadProviderConfigs(sharedAdminPool),
|
||||
]);
|
||||
|
||||
/**
|
||||
* Catch unhandled promise rejections and log them to Application Insights.
|
||||
* The unhandled promise rejection was first observed in the `TenantPool.get()` method.
|
||||
*
|
||||
* In this method, if the `tenantId` is not found, `Tenant.create()` will throw an error.
|
||||
* We use a try-catch block to catch the error and throw it with logging.
|
||||
* However, if the `Tenant.create()` Promise is read from the cache, somehow the error is not caught.
|
||||
* The root cause of this error is still unknown. To avoid the app from crashing, we catch the error here.
|
||||
*
|
||||
* @see TenantPool.get
|
||||
*/
|
||||
process.on('unhandledRejection', (error) => {
|
||||
consoleLog.error(error);
|
||||
void appInsights.trackException(error);
|
||||
});
|
||||
|
||||
await initApp(app);
|
||||
} catch (error: unknown) {
|
||||
consoleLog.error('Error while initializing app:');
|
||||
|
|
|
@ -51,7 +51,8 @@ export default class Tenant implements TenantContext {
|
|||
// 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));
|
||||
const tenantDatabaseDsn = await getTenantDatabaseDsn(id);
|
||||
const envSet = new EnvSet(id, tenantDatabaseDsn);
|
||||
// Custom endpoint is used for building OIDC issuer URL when the request is a custom domain
|
||||
await envSet.load(customDomain);
|
||||
|
||||
|
|
Loading…
Reference in a new issue