chore: add middleware for error handling #695

Merged
Sainan merged 3 commits from error-middleware into main 2025-01-03 13:25:03 -08:00
Owner
No description provided.
coderabbitai[bot] commented 2025-01-02 23:49:10 -08:00 (Migrated from github.com)
Author
Owner

Walkthrough

The pull request introduces a comprehensive refactoring of error handling and logging across multiple files in the application. The primary changes involve removing explicit logging of errors and replacing them with direct error throwing. A new centralized error handling middleware (errorHandler) has been added to src/middleware/errorHandler.ts, which provides a standardized approach to processing and responding to different types of errors.

The modifications span several services, controllers, and the main application configuration, focusing on simplifying error management. The changes include removing logger imports, deleting error logging statements, and ensuring that errors are thrown with descriptive messages. The new errorHandler middleware is designed to handle various error scenarios, providing consistent error responses and logging mechanisms for the application.

These changes represent a shift towards a more streamlined error handling approach, centralizing error processing and reducing scattered logging throughout the codebase.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.
<!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- walkthrough_start --> ## Walkthrough The pull request introduces a comprehensive refactoring of error handling and logging across multiple files in the application. The primary changes involve removing explicit logging of errors and replacing them with direct error throwing. A new centralized error handling middleware (`errorHandler`) has been added to `src/middleware/errorHandler.ts`, which provides a standardized approach to processing and responding to different types of errors. The modifications span several services, controllers, and the main application configuration, focusing on simplifying error management. The changes include removing logger imports, deleting error logging statements, and ensuring that errors are thrown with descriptive messages. The new `errorHandler` middleware is designed to handle various error scenarios, providing consistent error responses and logging mechanisms for the application. These changes represent a shift towards a more streamlined error handling approach, centralizing error processing and reducing scattered logging throughout the codebase. <!-- walkthrough_end --> <!-- internal state start --> <!-- FAHghAtBAEAqAWBLAztF0CGA7TBXALgPYQDmAplmQE4b5kAm0AxoQLasX4Bc0ADldEIAjAFZkm+RADcyqIQE9mhetQxChifADoMiaFAB8wY+CjHYmgDZkeTeISo3M9Rq0QvrAdwyPoAMwdoaipA+Gx6S0QsEmAAOVxWIWoeADYATgBWYABVZGToAGVdLGxjQxNIGApGQj88IlIKVTpGFnZOHn5BUXFJGTlFFhUadU0dP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QSoDMxJWpgs5oPuu5gKpdkwwq6K0q3IsaXVWqxDu7Z9qttdiK8vo7RKwHS7dK7YjvtDlq84gjsftmeUKAJUEBDUNfAQIsKTtdXvJsNsDdfCMcJSSMOcOMFcEYFMLBJoDIe4MgDIRbn2GHfQDIdjtSMF5l34FRkkAAIwpBCBUYABMAAzAAOz0D1f0B+BMDVcAAcTX1GDX1XGQfgPXFGDA9AaQVGFGSQFGI3GQ6XtwMA9o2XuX+XCywoDAMh5GhgQAA= --> <!-- internal state end --> <!-- tips_start --> --- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <details> <summary>🪧 Tips</summary> ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit <commit_id>, please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR. ([Beta](https://docs.coderabbit.ai/early-access#beta)) - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### Documentation and Community - Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements. </details> <!-- tips_end -->
coderabbitai[bot] (Migrated from github.com) reviewed 2025-01-02 23:50:48 -08:00
coderabbitai[bot] (Migrated from github.com) left a comment
Author
Owner

Actionable comments posted: 0

🧹 Nitpick comments (6)
src/services/loadoutService.ts (1)

7-7: Consider using specialized error classes or attaching a status code.
Throwing a generic Error is acceptable, but using a specialized error (e.g., NotFoundError) or attaching more context (e.g., error.status = 404) may improve handling and traceability in the errorHandler middleware.

src/services/personalRoomsService.ts (1)

7-7: Use a dedicated error class for better error identification.
Similar to getLoadout, consider using a custom error type indicating a "not found" condition or augmenting the error with a status code for clearer distinction in the errorHandler.

src/middleware/errorHandler.ts (3)

5-5: Use strict comparison for string matching.
Replace == with === to avoid unexpected type coercions.

-if (err.message == "Invalid accountId-nonce pair") {
+if (err.message === "Invalid accountId-nonce pair") {

7-11: Handle potential empty or missing stack.
When err.stack is undefined or empty, splitting might fail. Consider adding a guard clause or fallback in case err.stack is not a valid string.


4-16: General improvement for production environments.
Returning an error message or stack trace directly could accidentally leak internal details. If this is a production environment, consider obfuscating or removing sensitive information from the response.

src/controllers/api/getShipController.ts (1)

46-46: Use a more descriptive or specialized error type.

Throwing a raw Error aligns with the new approach of removing logging statements in favor of throwing errors. However, consider using a specialized error type or including additional status information so the errorHandler middleware can respond with more context (e.g., HTTP 404).

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f1c0c5a429 and f0be16b023.

📒 Files selected for processing (11)
  • src/app.ts (2 hunks)
  • src/controllers/api/claimCompletedRecipeController.ts (0 hunks)
  • src/controllers/api/getShipController.ts (1 hunks)
  • src/controllers/api/inventoryController.ts (1 hunks)
  • src/controllers/api/startRecipeController.ts (0 hunks)
  • src/middleware/errorHandler.ts (1 hunks)
  • src/services/itemDataService.ts (0 hunks)
  • src/services/loadoutService.ts (1 hunks)
  • src/services/personalRoomsService.ts (1 hunks)
  • src/services/shipCustomizationsService.ts (0 hunks)
  • src/services/shipService.ts (0 hunks)
💤 Files with no reviewable changes (5)
  • src/controllers/api/startRecipeController.ts
  • src/services/itemDataService.ts
  • src/controllers/api/claimCompletedRecipeController.ts
  • src/services/shipService.ts
  • src/services/shipCustomizationsService.ts
🔇 Additional comments (3)
src/app.ts (2)

5-5: Good practice: Keep error handling middleware logically last.
Ensure that the errorHandler is used after all routes (including unknownEndpointHandler) so that any unhandled endpoint or error is caught at the end.


24-24: Validate appropriate order of middleware usage.
Double-check that the requestLogger middleware properly logs before errorHandler intercepts. Consider placing errorHandler as the very last middleware in the stack, following the unknownEndpointHandler.

src/controllers/api/inventoryController.ts (1)

21-21: Consider verifying error propagation from getAccountForRequest.

Removing the try-catch and allowing errors to bubble up to the new centralized errorHandler follows the PR's approach. Ensure that this function throws a clear and descriptive error (e.g., authentication expired or invalid user request) so it can be gracefully handled and presented to the client through the middleware.

**Actionable comments posted: 0** <details> <summary>🧹 Nitpick comments (6)</summary><blockquote> <details> <summary>src/services/loadoutService.ts (1)</summary><blockquote> `7-7`: **Consider using specialized error classes or attaching a status code.** Throwing a generic `Error` is acceptable, but using a specialized error (e.g., `NotFoundError`) or attaching more context (e.g., `error.status = 404`) may improve handling and traceability in the `errorHandler` middleware. </blockquote></details> <details> <summary>src/services/personalRoomsService.ts (1)</summary><blockquote> `7-7`: **Use a dedicated error class for better error identification.** Similar to `getLoadout`, consider using a custom error type indicating a "not found" condition or augmenting the error with a status code for clearer distinction in the `errorHandler`. </blockquote></details> <details> <summary>src/middleware/errorHandler.ts (3)</summary><blockquote> `5-5`: **Use strict comparison for string matching.** Replace `==` with `===` to avoid unexpected type coercions. ```diff -if (err.message == "Invalid accountId-nonce pair") { +if (err.message === "Invalid accountId-nonce pair") { ``` --- `7-11`: **Handle potential empty or missing stack.** When `err.stack` is undefined or empty, splitting might fail. Consider adding a guard clause or fallback in case `err.stack` is not a valid string. --- `4-16`: **General improvement for production environments.** Returning an error message or stack trace directly could accidentally leak internal details. If this is a production environment, consider obfuscating or removing sensitive information from the response. </blockquote></details> <details> <summary>src/controllers/api/getShipController.ts (1)</summary><blockquote> `46-46`: **Use a more descriptive or specialized error type.** Throwing a raw `Error` aligns with the new approach of removing logging statements in favor of throwing errors. However, consider using a specialized error type or including additional status information so the `errorHandler` middleware can respond with more context (e.g., HTTP 404). </blockquote></details> </blockquote></details> <details> <summary>📜 Review details</summary> **Configuration used: .coderabbit.yaml** **Review profile: CHILL** **Plan: Pro** <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between f1c0c5a4297affdc1f013aa02486887f2c6fd141 and f0be16b0237db0dfc18340215f84edd904be4f85. </details> <details> <summary>📒 Files selected for processing (11)</summary> * `src/app.ts` (2 hunks) * `src/controllers/api/claimCompletedRecipeController.ts` (0 hunks) * `src/controllers/api/getShipController.ts` (1 hunks) * `src/controllers/api/inventoryController.ts` (1 hunks) * `src/controllers/api/startRecipeController.ts` (0 hunks) * `src/middleware/errorHandler.ts` (1 hunks) * `src/services/itemDataService.ts` (0 hunks) * `src/services/loadoutService.ts` (1 hunks) * `src/services/personalRoomsService.ts` (1 hunks) * `src/services/shipCustomizationsService.ts` (0 hunks) * `src/services/shipService.ts` (0 hunks) </details> <details> <summary>💤 Files with no reviewable changes (5)</summary> * src/controllers/api/startRecipeController.ts * src/services/itemDataService.ts * src/controllers/api/claimCompletedRecipeController.ts * src/services/shipService.ts * src/services/shipCustomizationsService.ts </details> <details> <summary>🔇 Additional comments (3)</summary><blockquote> <details> <summary>src/app.ts (2)</summary> `5-5`: **Good practice: Keep error handling middleware logically last.** Ensure that the `errorHandler` is used after all routes (including `unknownEndpointHandler`) so that any unhandled endpoint or error is caught at the end. --- `24-24`: **Validate appropriate order of middleware usage.** Double-check that the `requestLogger` middleware properly logs before `errorHandler` intercepts. Consider placing `errorHandler` as the very last middleware in the stack, following the `unknownEndpointHandler`. </details> <details> <summary>src/controllers/api/inventoryController.ts (1)</summary> `21-21`: **Consider verifying error propagation from `getAccountForRequest`.** Removing the `try-catch` and allowing errors to bubble up to the new centralized `errorHandler` follows the PR's approach. Ensure that this function throws a clear and descriptive error (e.g., authentication expired or invalid user request) so it can be gracefully handled and presented to the client through the middleware. </details> </blockquote></details> </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Sign in to join this conversation.
No description provided.