improve error message if sdk request fails
This commit is contained in:
@@ -18,7 +18,10 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
|||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const projectId = await validateSdkRequest(req.headers).catch(
|
const projectId = await validateSdkRequest(req.headers).catch(
|
||||||
logger.error
|
(error) => {
|
||||||
|
logger.error(error, 'Failed to validate sdk request');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
if (!projectId) {
|
if (!projectId) {
|
||||||
return reply.status(401).send();
|
return reply.status(401).send();
|
||||||
|
|||||||
@@ -7,9 +7,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).catch(
|
const projectId = await validateSdkRequest(req.headers).catch((error) => {
|
||||||
logger.error
|
logger.error(error, 'Failed to validate sdk request');
|
||||||
);
|
return null;
|
||||||
|
});
|
||||||
if (!projectId) {
|
if (!projectId) {
|
||||||
return reply.status(401).send();
|
return reply.status(401).send();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,11 +28,13 @@ export async function validateSdkRequest(
|
|||||||
throw new Error('Ingestion: Missing client id');
|
throw new Error('Ingestion: Missing client id');
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = await db.client.findUnique({
|
const client = await db.client
|
||||||
where: {
|
.findUnique({
|
||||||
id: clientId,
|
where: {
|
||||||
},
|
id: clientId,
|
||||||
});
|
},
|
||||||
|
})
|
||||||
|
.catch(() => null);
|
||||||
|
|
||||||
if (!client) {
|
if (!client) {
|
||||||
throw new Error('Ingestion: Invalid client id');
|
throw new Error('Ingestion: Invalid client id');
|
||||||
|
|||||||
Reference in New Issue
Block a user