Skip to content

refactor(server): refactor error handling using http code enum#6409

Merged
chenjiahan merged 5 commits intomainfrom
server_errors_1022
Oct 23, 2025
Merged

refactor(server): refactor error handling using http code enum#6409
chenjiahan merged 5 commits intomainfrom
server_errors_1022

Conversation

@chenjiahan
Copy link
Member

Summary

  • Refactor error handling using HttpCode enum
  • Improve logging for malicious and invalid paths

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings October 22, 2025 13:16
@netlify
Copy link

netlify bot commented Oct 22, 2025

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 0715bc1
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/68f9924d0940b20008771218
😎 Deploy Preview https://deploy-preview-6409--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 66 (🟢 up 12 from production)
Accessibility: 97 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors error handling in the assets middleware by introducing an HttpCode enum to replace magic numbers and improves logging for specific error cases.

  • Introduced HttpCode enum to replace hardcoded HTTP status codes throughout the middleware
  • Added explicit error logging for malicious paths (403) and invalid pathnames (400)
  • Refactored sendError function to accept HttpCode enum values and moved error message mapping inside the function

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
packages/core/src/server/assets-middleware/middleware.ts Introduced HttpCode enum, refactored sendError function signature, replaced magic numbers with enum values, and added error logging for BadRequest cases
packages/core/src/server/assets-middleware/getFileFromUrl.ts Updated return type to use HttpCode enum, inlined pathname decoding logic, and replaced magic numbers with enum values

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chenjiahan chenjiahan merged commit a8451b4 into main Oct 23, 2025
11 checks passed
@chenjiahan chenjiahan deleted the server_errors_1022 branch October 23, 2025 02:35
@chenjiahan chenjiahan mentioned this pull request Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant