diff --git a/apps/api/src/routes/event.router.ts b/apps/api/src/routes/event.router.ts index ed23ecf9..043525c0 100644 --- a/apps/api/src/routes/event.router.ts +++ b/apps/api/src/routes/event.router.ts @@ -18,13 +18,15 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => { ) => { try { const client = await validateSdkRequest(req.headers).catch((error) => { - if (!(error instanceof SdkAuthError)) { - logger.error(error, 'Failed to validate sdk request'); + if (error instanceof SdkAuthError) { + return reply.status(401).send(error.message); } - return null; + logger.error(error, 'Failed to validate sdk request'); + return reply.status(401).send('Unknown validation error'); }); + if (!client?.projectId) { - return reply.status(401).send(); + return reply.status(401).send('No project found for this client'); } req.projectId = client.projectId; req.client = client; diff --git a/apps/api/src/routes/profile.router.ts b/apps/api/src/routes/profile.router.ts index 891ddeaf..b0c534c8 100644 --- a/apps/api/src/routes/profile.router.ts +++ b/apps/api/src/routes/profile.router.ts @@ -8,13 +8,15 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => { fastify.addHook('preHandler', async (req, reply) => { try { const client = await validateSdkRequest(req.headers).catch((error) => { - if (!(error instanceof SdkAuthError)) { - logger.error(error, 'Failed to validate sdk request'); + if (error instanceof SdkAuthError) { + return reply.status(401).send(error.message); } - return null; + logger.error(error, 'Failed to validate sdk request'); + return reply.status(401).send('Unknown validation error'); }); + if (!client?.projectId) { - return reply.status(401).send(); + return reply.status(401).send('No project found for this client'); } req.projectId = client.projectId; req.client = client; diff --git a/apps/api/src/routes/track.router.ts b/apps/api/src/routes/track.router.ts index 3cedf61e..8849b35e 100644 --- a/apps/api/src/routes/track.router.ts +++ b/apps/api/src/routes/track.router.ts @@ -18,14 +18,15 @@ const trackRouter: FastifyPluginCallback = (fastify, opts, done) => { ) => { try { const client = await validateSdkRequest(req.headers).catch((error) => { - if (!(error instanceof SdkAuthError)) { - logger.error(error, 'Failed to validate sdk request'); + if (error instanceof SdkAuthError) { + return reply.status(401).send(error.message); } - return null; + logger.error(error, 'Failed to validate sdk request'); + return reply.status(401).send('Unknown validation error'); }); if (!client?.projectId) { - return reply.status(401).send(); + return reply.status(401).send('No project found for this client'); } req.projectId = client.projectId;