improve sdk error logging

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-07-17 22:52:14 +02:00
parent f3ab307e87
commit 1728a75b19
3 changed files with 9 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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) {