Skip to content

Latest commit

 

History

History
39 lines (30 loc) · 1.46 KB

File metadata and controls

39 lines (30 loc) · 1.46 KB

Solution for Issue #124

🛠️ Proposed Solution (by Aditya Waghamare)

Analysis

The issue requests adding a test (using Supertest) to verify that requests exceeding the bodySizeLimit (default 1mb) correctly return a 413 Payload Too Large status code (along with a structured error envelope success: false) rather than falling through to a generic 500 Internal Server Error.

Fix

Add a comprehensive integration test in the backend test suite verifying the payload size limit error handling behavior.

Implementation

import request from 'supertest';
import app from '../../src/app';

describe('Payload Size Limit Middleware', () => {
  it('should return 413 Payload Too Large when request body exceeds bodySizeLimit', async () => {
    // Generate a payload larger than 1MB (e.g., 2MB of 'a' characters)
    const largePayload = {
      data: 'a'.repeat(2 * 1024 * 1024),
    };

    const response = await request(app)
      .post('/api/v1/agents')
      .send(largePayload)
      .set('Content-Type', 'application/json');

    expect(response.status).toBe(413);
    expect(response.body).toHaveProperty('success', false);
  });
});

Testing

Run the test suite using npm test or jest to verify that oversized payloads are correctly caught, handled with status 413, and return a consistent error response structure.


Submitted by Aditya Waghamare 💰 Payout Address (Base L2 / EVM): 0xb61dBcdBc3407F71EaCb64D4CBFAcf9FFfe2415C