improve sdk error logging
This commit is contained in:
@@ -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) => {
|
||||||
logger.error(error, 'Failed to validate sdk request');
|
if (!(error instanceof SdkAuthError)) {
|
||||||
|
logger.error(error, 'Failed to validate sdk request');
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
if (!client?.projectId) {
|
if (!client?.projectId) {
|
||||||
|
|||||||
@@ -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) => {
|
||||||
logger.error(error, 'Failed to validate sdk request');
|
if (!(error instanceof SdkAuthError)) {
|
||||||
|
logger.error(error, 'Failed to validate sdk request');
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
if (!client?.projectId) {
|
if (!client?.projectId) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user