Skip to content

chore: Add test coverage for multipart BodyLimit error handling#4237

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-multipart-form-error-handling
Draft

chore: Add test coverage for multipart BodyLimit error handling#4237
Copilot wants to merge 2 commits intomainfrom
copilot/fix-multipart-form-error-handling

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 25, 2026

Description

Oversized multipart uploads were reported as bypassing custom ErrorHandler responses and surfacing as a generic client-side network error instead of a 413 response. This PR adds regression coverage for that path so multipart requests exceeding BodyLimit are verified to return the same custom error response shape as other oversized requests.

  • What changed

    • Added an integration test for oversized multipart/form-data requests handled through a custom ErrorHandler
    • Asserted the response status remains 413 Request Entity Too Large
    • Asserted the custom handler response body and content type are preserved for multipart uploads
  • Regression coverage

    • Exercises the server-level oversized body path with a real multipart payload
    • Verifies the error is translated into *fiber.Error and serialized by the app’s custom error handler, rather than failing as a transport-level "error" on the client
  • Example

    app := fiber.New(fiber.Config{
        BodyLimit: 128,
        ErrorHandler: func(c fiber.Ctx, err error) error {
            code := fiber.StatusInternalServerError
            var fiberErr *fiber.Error
            if errors.As(err, &fiberErr) {
                code = fiberErr.Code
            }
    
            return c.Status(code).JSON(fiber.Map{
                "code":    code,
                "message": err.Error(),
            })
        },
    })

Changes introduced

List the new features or adjustments introduced in this pull request. Provide details on benchmarks, documentation updates, changelog entries, and if applicable, the migration guide.

  • Benchmarks: Describe any performance benchmarks and improvements related to the changes.
  • Documentation Update: Detail the updates made to the documentation and links to the changed files.
  • Changelog/What's New: Include a summary of the additions for the upcoming release notes.
  • Migration Guide: If necessary, provide a guide or steps for users to migrate their existing code to accommodate these changes.
  • API Alignment with Express: Explain how the changes align with the Express API.
  • API Longevity: Discuss the steps taken to ensure that the new or updated APIs are consistent and not prone to breaking changes.
  • Examples: Provide examples demonstrating the new features or changes in action.

Type of change

Please delete options that are not relevant.

  • New feature (non-breaking change which adds functionality)
  • Enhancement (improvement to existing features and functionality)
  • Documentation update (changes to documentation)
  • Performance improvement (non-breaking change which improves efficiency)
  • Code consistency (non-breaking change which improves code reliability and robustness)

Checklist

Before you submit your pull request, please make sure you meet these requirements:

  • Followed the inspiration of the Express.js framework for new functionalities, making them similar in usage.
  • Conducted a self-review of the code and provided comments for complex or critical parts.
  • Updated the documentation in the /docs/ directory for Fiber's documentation.
  • Added or updated unit tests to validate the effectiveness of the changes or new features.
  • Ensured that new and existing unit tests pass locally with the changes.
  • Verified that any new dependencies are essential and have been agreed upon by the maintainers/community.
  • Aimed for optimal performance with minimal allocations in the new code.
  • Provided benchmarks for the new code to analyze and improve upon.

Commit formatting

Please use emojis in commit messages for an easy way to identify the purpose or intention of a commit. Check out the emoji cheatsheet here: CONTRIBUTING.md

Copilot AI linked an issue Apr 25, 2026 that may be closed by this pull request
3 tasks
Copilot AI changed the title [WIP] Fix error handling for multipart forms exceeding BodyLimit 🐛 bug: cover multipart BodyLimit error handling with a regression test Apr 25, 2026
Copilot AI requested a review from gaby April 25, 2026 21:44
Copilot finished work on behalf of gaby April 25, 2026 21:44
@ReneWerner87 ReneWerner87 added this to v3 Apr 25, 2026
@ReneWerner87 ReneWerner87 added this to the v3 milestone Apr 25, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.17%. Comparing base (bec9ba6) to head (42521fc).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4237   +/-   ##
=======================================
  Coverage   91.17%   91.17%           
=======================================
  Files         123      123           
  Lines       12084    12084           
=======================================
  Hits        11018    11018           
  Misses        668      668           
  Partials      398      398           
Flag Coverage Δ
unittests 91.17% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gaby gaby changed the title 🐛 bug: cover multipart BodyLimit error handling with a regression test chore: Add test coverage for multipart BodyLimit error handling Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: 413 not returned back to firefox

3 participants