improve error message when client validation fails
This commit is contained in:
@@ -18,13 +18,15 @@ const eventRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
|||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const client = await validateSdkRequest(req.headers).catch((error) => {
|
const client = await validateSdkRequest(req.headers).catch((error) => {
|
||||||
if (!(error instanceof SdkAuthError)) {
|
if (error instanceof SdkAuthError) {
|
||||||
logger.error(error, 'Failed to validate sdk request');
|
return reply.status(401).send(error.message);
|
||||||
}
|
}
|
||||||
return null;
|
logger.error(error, 'Failed to validate sdk request');
|
||||||
|
return reply.status(401).send('Unknown validation error');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!client?.projectId) {
|
if (!client?.projectId) {
|
||||||
return reply.status(401).send();
|
return reply.status(401).send('No project found for this client');
|
||||||
}
|
}
|
||||||
req.projectId = client.projectId;
|
req.projectId = client.projectId;
|
||||||
req.client = client;
|
req.client = client;
|
||||||
|
|||||||
@@ -8,13 +8,15 @@ 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) => {
|
||||||
if (!(error instanceof SdkAuthError)) {
|
if (error instanceof SdkAuthError) {
|
||||||
logger.error(error, 'Failed to validate sdk request');
|
return reply.status(401).send(error.message);
|
||||||
}
|
}
|
||||||
return null;
|
logger.error(error, 'Failed to validate sdk request');
|
||||||
|
return reply.status(401).send('Unknown validation error');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!client?.projectId) {
|
if (!client?.projectId) {
|
||||||
return reply.status(401).send();
|
return reply.status(401).send('No project found for this client');
|
||||||
}
|
}
|
||||||
req.projectId = client.projectId;
|
req.projectId = client.projectId;
|
||||||
req.client = client;
|
req.client = client;
|
||||||
|
|||||||
@@ -18,14 +18,15 @@ const trackRouter: FastifyPluginCallback = (fastify, opts, done) => {
|
|||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const client = await validateSdkRequest(req.headers).catch((error) => {
|
const client = await validateSdkRequest(req.headers).catch((error) => {
|
||||||
if (!(error instanceof SdkAuthError)) {
|
if (error instanceof SdkAuthError) {
|
||||||
logger.error(error, 'Failed to validate sdk request');
|
return reply.status(401).send(error.message);
|
||||||
}
|
}
|
||||||
return null;
|
logger.error(error, 'Failed to validate sdk request');
|
||||||
|
return reply.status(401).send('Unknown validation error');
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!client?.projectId) {
|
if (!client?.projectId) {
|
||||||
return reply.status(401).send();
|
return reply.status(401).send('No project found for this client');
|
||||||
}
|
}
|
||||||
|
|
||||||
req.projectId = client.projectId;
|
req.projectId = client.projectId;
|
||||||
|
|||||||
Reference in New Issue
Block a user