Skip to content

Commit 52b7d7e

Browse files
authored
Merge pull request #726 from divysam/feat/request-body-size-limits-569
feat(backend): add request body size limits and campaign description validation (#569)
2 parents b3d3b4e + ac6da0d commit 52b7d7e

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

backend/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ app.use((err: unknown, req: Request, res: Response, next: express.NextFunction)
864864
success: false,
865865
error: {
866866
code: 'PAYLOAD_TOO_LARGE',
867-
message: 'Request payload size exceeds the maximum allowed limit',
867+
message: `Request body exceeds the ${bodySizeLimit} maximum limit.`,
868868
requestId: (req as RequestWithId).requestId,
869869
},
870870
});

backend/src/openapi.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ const validationErrorResponse = {
428428
content: { 'application/json': { schema: registeredSchemas.ApiError } },
429429
};
430430

431+
const payloadTooLargeResponse = {
432+
description: 'Request body exceeds the 64KB maximum limit',
433+
content: { 'application/json': { schema: registeredSchemas.ApiError } },
434+
};
435+
431436
registry.registerPath({
432437
method: 'get',
433438
path: '/api/health',
@@ -537,6 +542,7 @@ registry.registerPath({
537542
content: { 'application/json': { schema: registeredSchemas.CampaignDetailResponse } },
538543
},
539544
400: validationErrorResponse,
545+
413: payloadTooLargeResponse,
540546
},
541547
});
542548

@@ -638,6 +644,7 @@ registry.registerPath({
638644
},
639645
400: validationErrorResponse,
640646
404: notFoundResponse,
647+
413: payloadTooLargeResponse,
641648
429: { description: 'Rate limit exceeded' },
642649
},
643650
});
@@ -662,6 +669,7 @@ registry.registerPath({
662669
},
663670
400: validationErrorResponse,
664671
404: notFoundResponse,
672+
413: payloadTooLargeResponse,
665673
429: { description: 'Rate limit exceeded' },
666674
},
667675
});
@@ -686,6 +694,7 @@ registry.registerPath({
686694
},
687695
400: validationErrorResponse,
688696
404: notFoundResponse,
697+
413: payloadTooLargeResponse,
689698
429: { description: 'Rate limit exceeded' },
690699
},
691700
});
@@ -711,6 +720,7 @@ registry.registerPath({
711720
},
712721
400: validationErrorResponse,
713722
404: notFoundResponse,
723+
413: payloadTooLargeResponse,
714724
429: { description: 'Rate limit exceeded' },
715725
},
716726
});

backend/src/services/cache.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ export async function initRedisCache(): Promise<void> {
3131
await redisClient.connect();
3232
isConnected = true;
3333

34+
logInfo('redis_connected', {}, config.logLevel);
35+
} catch (error) {
36+
logError(error instanceof Error ? error : new Error(String(error)), { event: 'redis_connection_failed' }, config.logLevel);
3437
redisClient = null;
3538
isConnected = false;
3639
} catch {

0 commit comments

Comments
 (0)