fix: use proper HTTP status codes on peer/ensure (400 for validation, 429 for rate limit)

This commit is contained in:
Jannis Braun
2026-04-09 13:47:30 +02:00
parent 051646763a
commit 63a7f0c922
+9 -3
View File
@@ -490,16 +490,22 @@ export async function federationRoutes(app: FastifyInstance): Promise<void> {
async (request, reply) => { async (request, reply) => {
const { remoteOrigin: rawOrigin } = request.body ?? {}; const { remoteOrigin: rawOrigin } = request.body ?? {};
if (!rawOrigin || typeof rawOrigin !== 'string') { if (!rawOrigin || typeof rawOrigin !== 'string') {
return reply.code(200).send({ peeringStatus: 'failed', error: 'remoteOrigin is required' }); return reply.code(400).send({ error: 'remoteOrigin is required', statusCode: 400 });
} }
const remoteOrigin = validateOrigin(rawOrigin); const remoteOrigin = validateOrigin(rawOrigin);
if (!remoteOrigin) { if (!remoteOrigin) {
return reply.code(200).send({ peeringStatus: 'failed', error: 'remoteOrigin must be a valid HTTPS URL (HTTP is only allowed for localhost)' }); return reply.code(400).send({
error: 'remoteOrigin must be a valid HTTPS URL (HTTP is only allowed for localhost)',
statusCode: 400,
});
} }
if (isEnsureRateLimited(request.userId)) { if (isEnsureRateLimited(request.userId)) {
return reply.code(200).send({ peeringStatus: 'failed', error: 'Too many peering requests — try again later' }); return reply.code(429).send({
error: 'Too many peering requests — try again later',
statusCode: 429,
});
} }
const { ensurePeered } = await import('../utils/federationPeering.js'); const { ensurePeered } = await import('../utils/federationPeering.js');