fix(api): handle common errors better

This commit is contained in:
Carl-Gerhard Lindesvärd
2025-01-28 07:14:35 +00:00
parent 8bbf36473b
commit 7deee7e4c2
4 changed files with 63 additions and 7 deletions

View File

@@ -1,12 +1,8 @@
import { isBot } from '@/bots';
import { handler } from '@/controllers/track.controller';
import { SdkAuthError, validateSdkRequest } from '@/utils/auth';
import type { FastifyPluginCallback, FastifyRequest } from 'fastify';
import type { FastifyPluginCallback } from 'fastify';
import { clientHook } from '@/hooks/client.hook';
import { isBotHook } from '@/hooks/is-bot.hook';
import { createBotEvent } from '@openpanel/db';
import type { TrackHandlerPayload } from '@openpanel/sdk';
const trackRouter: FastifyPluginCallback = (fastify, opts, done) => {
fastify.addHook('preHandler', clientHook);
@@ -16,6 +12,22 @@ const trackRouter: FastifyPluginCallback = (fastify, opts, done) => {
method: 'POST',
url: '/',
handler: handler,
schema: {
body: {
type: 'object',
required: ['type', 'payload'],
properties: {
type: {
type: 'string',
enum: ['track', 'increment', 'decrement', 'alias', 'identify'],
},
payload: {
type: 'object',
additionalProperties: true,
},
},
},
},
});
done();