diff --git a/packages/api/src/queue-processor.ts b/packages/api/src/queue-processor.ts index 6cd13b8a0..959c866fc 100644 --- a/packages/api/src/queue-processor.ts +++ b/packages/api/src/queue-processor.ts @@ -13,6 +13,7 @@ import { import express, { Express } from 'express' import { appDataSource } from './data_source' import { env } from './env' +import { aiSummarize, AI_SUMMARIZE_JOB_NAME } from './jobs/ai-summarize' import { bulkAction, BULK_ACTION_JOB_NAME } from './jobs/bulk_action' import { callWebhook, CALL_WEBHOOK_JOB_NAME } from './jobs/call_webhook' import { findThumbnail, THUMBNAIL_JOB } from './jobs/find_thumbnail' @@ -43,7 +44,6 @@ import { redisDataSource } from './redis_data_source' import { CACHED_READING_POSITION_PREFIX } from './services/cached_reading_position' import { getJobPriority } from './utils/createTask' import { logger } from './utils/logger' -import { AI_SUMMARIZE_JOB_NAME, aiSummarize } from './jobs/ai-summarize' export const QUEUE_NAME = 'omnivore-backend-queue' export const JOB_VERSION = 'v001' @@ -256,6 +256,16 @@ const main = async () => { process.on('SIGINT', () => gracefulShutdown('SIGINT')) process.on('SIGTERM', () => gracefulShutdown('SIGTERM')) + + process.on('uncaughtException', function (err) { + // Handle the error safely + logger.error('Uncaught exception', err) + }) + + process.on('unhandledRejection', (reason, promise) => { + // Handle the error safely + logger.error('Unhandled Rejection at: Promise', { promise, reason }) + }) } // only call main if the file was called from the CLI and wasn't required from another module diff --git a/packages/api/src/server.ts b/packages/api/src/server.ts index 135a9c4f9..995f7f289 100755 --- a/packages/api/src/server.ts +++ b/packages/api/src/server.ts @@ -47,7 +47,7 @@ import { isSystemRequest, } from './utils/auth' import { corsConfig } from './utils/corsConfig' -import { buildLogger, buildLoggerTransport } from './utils/logger' +import { buildLogger, buildLoggerTransport, logger } from './utils/logger' import { aiSummariesRouter } from './routers/ai_summary_router' const PORT = process.env.PORT || 4000 @@ -247,6 +247,16 @@ const main = async (): Promise => { process.on('SIGINT', () => gracefulShutdown('SIGINT')) process.on('SIGTERM', () => gracefulShutdown('SIGTERM')) + + process.on('uncaughtException', function (err) { + // Handle the error safely + logger.error('Uncaught exception', err) + }) + + process.on('unhandledRejection', (reason, promise) => { + // Handle the error safely + logger.error('Unhandled Rejection at: Promise', { promise, reason }) + }) } // only call main if the file was called from the CLI and wasn't required from another module