better handling unauth request
This commit is contained in:
@@ -16,7 +16,12 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
|||||||
reply
|
reply
|
||||||
) => {
|
) => {
|
||||||
try {
|
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;
|
req.projectId = projectId;
|
||||||
|
|
||||||
const bot = req.headers['user-agent']
|
const bot = req.headers['user-agent']
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import type { FastifyPluginCallback } from 'fastify';
|
|||||||
const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
||||||
fastify.addHook('preHandler', async (req, reply) => {
|
fastify.addHook('preHandler', async (req, reply) => {
|
||||||
try {
|
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;
|
req.projectId = projectId;
|
||||||
|
|
||||||
const bot = req.headers['user-agent']
|
const bot = req.headers['user-agent']
|
||||||
|
|||||||
Reference in New Issue
Block a user