better handling unauth request

This commit is contained in:
Carl-Gerhard Lindesvärd
2024-03-13 12:06:43 +01:00
parent f70cdee934
commit 4b3ce772ba
2 changed files with 10 additions and 2 deletions

View File

@@ -16,7 +16,12 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
reply
) => {
try {
const projectId = await validateSdkRequest(req.headers);
const projectId = await validateSdkRequest(req.headers).catch(
() => null
);
if (!projectId) {
return reply.status(401).send();
}
req.projectId = projectId;
const bot = req.headers['user-agent']

View File

@@ -6,7 +6,10 @@ import type { FastifyPluginCallback } from 'fastify';
const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
fastify.addHook('preHandler', async (req, reply) => {
try {
const projectId = await validateSdkRequest(req.headers);
const projectId = await validateSdkRequest(req.headers).catch(() => null);
if (!projectId) {
return reply.status(401).send();
}
req.projectId = projectId;
const bot = req.headers['user-agent']