Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

improve error message if sdk request fails

Carl-Gerhard Lindesvärd26909808de4c
diff --git a/apps/api/src/routes/event.router.ts b/apps/api/src/routes/event.router.ts
index da9ef4684..59c31bacb 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 8536352d1..dfc661057 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 0f99786d0..05791b45d 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');