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 { isBot } from '@/bots';
import * as controller from '@/controllers/event.controller'; import * as controller from '@/controllers/event.controller';
import { validateSdkRequest } from '@/utils/auth'; import { SdkAuthError, validateSdkRequest } from '@/utils/auth';
import { logger } from '@/utils/logger'; import { logger } from '@/utils/logger';
import type { FastifyPluginCallback, FastifyRequest } from 'fastify'; import type { FastifyPluginCallback, FastifyRequest } from 'fastify';
@@ -18,7 +18,9 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
) => { ) => {
try { try {
const client = await validateSdkRequest(req.headers).catch((error) => { const client = await validateSdkRequest(req.headers).catch((error) => {
if (!(error instanceof SdkAuthError)) {
logger.error(error, 'Failed to validate sdk request'); logger.error(error, 'Failed to validate sdk request');
}
return null; return null;
}); });
if (!client?.projectId) { if (!client?.projectId) {

View File

@@ -1,6 +1,6 @@
import { isBot } from '@/bots'; import { isBot } from '@/bots';
import * as controller from '@/controllers/profile.controller'; import * as controller from '@/controllers/profile.controller';
import { validateSdkRequest } from '@/utils/auth'; import { SdkAuthError, validateSdkRequest } from '@/utils/auth';
import { logger } from '@/utils/logger'; import { logger } from '@/utils/logger';
import type { FastifyPluginCallback } from 'fastify'; import type { FastifyPluginCallback } from 'fastify';
@@ -8,7 +8,9 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
fastify.addHook('preHandler', async (req, reply) => { fastify.addHook('preHandler', async (req, reply) => {
try { try {
const client = await validateSdkRequest(req.headers).catch((error) => { const client = await validateSdkRequest(req.headers).catch((error) => {
if (!(error instanceof SdkAuthError)) {
logger.error(error, 'Failed to validate sdk request'); logger.error(error, 'Failed to validate sdk request');
}
return null; return null;
}); });
if (!client?.projectId) { if (!client?.projectId) {

View File

@@ -11,7 +11,7 @@ const cleanDomain = (domain: string) =>
.replace(/https?:\/\//, '') .replace(/https?:\/\//, '')
.replace(/\/$/, ''); .replace(/\/$/, '');
class SdkAuthError extends Error { export class SdkAuthError extends Error {
payload: { payload: {
clientId?: string; clientId?: string;
clientSecret?: string; clientSecret?: string;