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

@@ -49,7 +49,7 @@ function getIdentity(body: TrackHandlerPayload): IdentifyPayload | undefined {
return (
identity ||
(body.payload.profileId
(body?.payload?.profileId
? {
profileId: body.payload.profileId,
}
@@ -100,7 +100,11 @@ export async function handler(
const projectId = request.client?.projectId;
if (!projectId) {
reply.status(400).send('missing origin');
reply.status(400).send({
status: 400,
error: 'Bad Request',
message: 'Missing projectId',
});
return;
}
@@ -198,6 +202,14 @@ export async function handler(
});
break;
}
default: {
reply.status(400).send({
status: 400,
error: 'Bad Request',
message: 'Invalid type',
});
break;
}
}
}