OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.
improve sdk error logging
Carl-Gerhard Lindesvärd1728a75b194b
diff --git a/apps/api/src/routes/event.router.ts b/apps/api/src/routes/event.router.tsindex c48e1e50f..ed23ecf90 100644--- a/apps/api/src/routes/event.router.ts+++ b/apps/api/src/routes/event.router.ts@@ -1,6 +1,6 @@import { isBot } from '@/bots';import * as controller from '@/controllers/event.controller';-import { validateSdkRequest } from '@/utils/auth';+import { SdkAuthError, validateSdkRequest } from '@/utils/auth';import { logger } from '@/utils/logger';import type { FastifyPluginCallback, FastifyRequest } from 'fastify';@@ -18,7 +18,9 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {) => {try {const client = await validateSdkRequest(req.headers).catch((error) => {- logger.error(error, 'Failed to validate sdk request');+ if (!(error instanceof SdkAuthError)) {+ logger.error(error, 'Failed to validate sdk request');+ }return null;});if (!client?.projectId) {diff --git a/apps/api/src/routes/profile.router.ts b/apps/api/src/routes/profile.router.tsindex 2c9f11112..891ddeaf0 100644--- a/apps/api/src/routes/profile.router.ts+++ b/apps/api/src/routes/profile.router.ts@@ -1,6 +1,6 @@import { isBot } from '@/bots';import * as controller from '@/controllers/profile.controller';-import { validateSdkRequest } from '@/utils/auth';+import { SdkAuthError, validateSdkRequest } from '@/utils/auth';import { logger } from '@/utils/logger';import type { FastifyPluginCallback } from 'fastify';@@ -8,7 +8,9 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {fastify.addHook('preHandler', async (req, reply) => {try {const client = await validateSdkRequest(req.headers).catch((error) => {- logger.error(error, 'Failed to validate sdk request');+ if (!(error instanceof SdkAuthError)) {+ logger.error(error, 'Failed to validate sdk request');+ }return null;});if (!client?.projectId) {diff --git a/apps/api/src/utils/auth.ts b/apps/api/src/utils/auth.tsindex 83c2574fc..43fd9b384 100644--- a/apps/api/src/utils/auth.ts+++ b/apps/api/src/utils/auth.ts@@ -11,7 +11,7 @@ const cleanDomain = (domain: string) =>.replace(/https?:\/\//, '').replace(/\/$/, '');-class SdkAuthError extends Error {+export class SdkAuthError extends Error {payload: {clientId?: string;clientSecret?: string;