diff --git a/apps/api/src/routes/event.router.ts b/apps/api/src/routes/event.router.ts index da9ef468..59c31bac 100644 --- a/apps/api/src/routes/event.router.ts +++ b/apps/api/src/routes/event.router.ts @@ -18,7 +18,10 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => { ) => { try { const projectId = await validateSdkRequest(req.headers).catch( - logger.error + (error) => { + logger.error(error, 'Failed to validate sdk request'); + return null; + } ); if (!projectId) { return reply.status(401).send(); diff --git a/apps/api/src/routes/profile.router.ts b/apps/api/src/routes/profile.router.ts index 8536352d..dfc66105 100644 --- a/apps/api/src/routes/profile.router.ts +++ b/apps/api/src/routes/profile.router.ts @@ -7,9 +7,10 @@ import type { FastifyPluginCallback } from 'fastify'; const eventRouter: FastifyPluginCallback = (fastify, opts, done) => { fastify.addHook('preHandler', async (req, reply) => { try { - const projectId = await validateSdkRequest(req.headers).catch( - logger.error - ); + const projectId = await validateSdkRequest(req.headers).catch((error) => { + logger.error(error, 'Failed to validate sdk request'); + return null; + }); if (!projectId) { return reply.status(401).send(); } diff --git a/apps/api/src/utils/auth.ts b/apps/api/src/utils/auth.ts index 0f99786d..05791b45 100644 --- a/apps/api/src/utils/auth.ts +++ b/apps/api/src/utils/auth.ts @@ -28,11 +28,13 @@ export async function validateSdkRequest( throw new Error('Ingestion: Missing client id'); } - const client = await db.client.findUnique({ - where: { - id: clientId, - }, - }); + const client = await db.client + .findUnique({ + where: { + id: clientId, + }, + }) + .catch(() => null); if (!client) { throw new Error('Ingestion: Invalid client id');