fix(error-handling-middleware): handle str error as ApiError#287
Merged
fix(error-handling-middleware): handle str error as ApiError#287
Conversation
There was a problem hiding this comment.
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
lib/response.js:607
- Consider ensuring that 'errorToSend' is always an instance of Error before passing it to 'app.catchErrors' to maintain consistent error handling.
this.app.catchErrors(errorToSend, this, statusCode, errorDetail);
index.js:360
- [nitpick] The variable name 'wasStringError' may be ambiguous; consider renaming it to something more descriptive like 'isResponseErrorFromString' to improve clarity.
const wasStringError = e instanceof ResponseError && e.originalMessage !== undefined;
There was a problem hiding this comment.
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (3)
lib/response.js:595
- The logic for assigning message, statusCode, and errorDetail is non-intuitive. Please add inline comments to clarify how the conditions distinguish between a string error and an error object.
error(code, e, detail) {
lib/response.js:603
- Only converting errors with a string message to ApiError may lead to unexpected handling of non-string errors. Verify that this conditional behavior is intentional and covers all error cases.
const errorToSend = typeof message === 'string' ? new ApiError(message, statusCode, errorDetail) : message;
index.js:355
- ApiError instances are logged in a different branch from other Error instances. Please confirm that this distinction in logging levels is intentional for proper error categorization.
const isApiError = e instanceof ApiError;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Before, when using
res.error(message), the message would be sent as string and not as an Error object to the error handling middleware.This PR adds a new error type called
ApiErrorand this error will be sent to the error handling middleware.Issue
Fixes #286