-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add notifications when there is an error in the service #264
Conversation
WalkthroughThe recent updates across multiple services and hooks focus on enhancing error handling by providing clearer and more descriptive exceptions. Improvements include structured error messages that offer additional context, such as causes and descriptions for various exceptions. Additionally, the JWT authentication logic in the Changes
Assessment against linked issues
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (1)
backend/src/auth/jwt.guard.ts (1)
1-11
: Ensure thejsonwebtoken
package is installed.The
jsonwebtoken
package is not listed in the dependencies of thebackend
orfrontend
package.json
files. Please add it to thedependencies
section in the appropriatepackage.json
file.
backend/package.json
frontend/package.json
Analysis chain
Ensure the
jsonwebtoken
package is installed.The new import for
jsonwebtoken
requires the package to be installed. Verify that it is included in the dependencies.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that `jsonwebtoken` is included in the dependencies. # Test: Check for `jsonwebtoken` in package.json. Expect: It should be listed as a dependency. rg --files-with-matches 'jsonwebtoken' package.jsonLength of output: 104
Script:
#!/bin/bash # Description: Locate the package.json file and verify that `jsonwebtoken` is included in the dependencies. # Step 1: Locate the package.json file PACKAGE_JSON_PATH=$(fd package.json) # Step 2: Check for `jsonwebtoken` in the located package.json file if [[ -n "$PACKAGE_JSON_PATH" ]]; then rg --files-with-matches 'jsonwebtoken' "$PACKAGE_JSON_PATH" else echo "package.json not found" fiLength of output: 304
Script:
#!/bin/bash # Description: Verify that `jsonwebtoken` is included in the dependencies of each package.json file. # Step 1: Locate all package.json files fd package.json --exec rg --files-with-matches 'jsonwebtoken' {}Length of output: 66
Script:
#!/bin/bash # Description: Print the contents of each package.json file to manually verify the presence of `jsonwebtoken`. # Step 1: Locate all package.json files fd package.json --exec cat {}Length of output: 5452
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (9)
- backend/src/auth/jwt.guard.ts (2 hunks)
- backend/src/documents/documents.service.ts (2 hunks)
- backend/src/files/files.service.ts (3 hunks)
- backend/src/intelligence/intelligence.service.ts (1 hunks)
- backend/src/users/users.service.ts (1 hunks)
- backend/src/workspace-documents/workspace-documents.service.ts (4 hunks)
- backend/src/workspace-users/workspace-users.service.ts (1 hunks)
- backend/src/workspaces/workspaces.service.ts (5 hunks)
- frontend/src/hooks/useErrorHandler.ts (1 hunks)
Additional comments not posted (24)
frontend/src/hooks/useErrorHandler.ts (2)
4-12
: TheCustomError
interface is well-defined.This interface extends the built-in
Error
type and adds necessary properties for enhanced error handling.
17-21
: TheuseErrorHandler
function improvements are approved.The function now provides more specific feedback based on the response structure, enhancing error handling.
backend/src/workspace-users/workspace-users.service.ts (1)
24-28
: Enhanced error handling is approved.The
NotFoundException
now includes a custom error message and additional details, improving clarity and user feedback.backend/src/documents/documents.service.ts (2)
34-37
: EnhancedUnauthorizedException
handling is approved.The
UnauthorizedException
now includes a custom error message and additional details, improving clarity and user feedback.
49-52
: EnhancedNotFoundException
handling is approved.The
NotFoundException
now includes a custom error message and additional details, improving clarity and user feedback.backend/src/auth/jwt.guard.ts (3)
15-18
: LGTM! EnsureConfigService
is correctly configured.The
ConfigService
is correctly injected. Ensure that it is properly configured in the application module.
31-44
: LGTM! Verify the correctness of token retrieval and verification.The new logic for token retrieval and verification looks good. Ensure that the token is correctly retrieved from the headers and verified using the secret key.
45-61
: LGTM! Verify the error handling logic.The error handling logic distinguishes between different error types and provides clear feedback. Ensure that the error messages are correctly displayed to the user.
backend/src/users/users.service.ts (1)
77-80
: LGTM! The enhanced error handling improves clarity.The new error handling logic provides a clear and informative message when a nickname conflict occurs.
backend/src/intelligence/intelligence.service.ts (1)
28-32
: LGTM! The enhanced error handling improves clarity.The new error handling logic provides a clear and informative message when a feature is not found.
backend/src/files/files.service.ts (4)
49-52
: Enhanced UnauthorizedException message.The detailed message and structured error object improve clarity. This change is approved.
56-59
: Enhanced UnprocessableEntityException message.The detailed message and structured error object improve clarity. This change is approved.
84-87
: Enhanced NotFoundException message.The detailed message and structured error object improve clarity. This change is approved.
104-107
: Enhanced BadRequestException message.The detailed message and structured error object improve clarity. This change is approved.
backend/src/workspaces/workspaces.service.ts (5)
28-31
: Enhanced ConflictException message.The detailed message and structured error object improve clarity. This change is approved.
69-72
: Enhanced NotFoundException message.The detailed message and structured error object improve clarity. This change is approved.
123-127
: Enhanced NotFoundException message.The detailed message and structured error object improve clarity. This change is approved.
165-168
: Enhanced UnauthorizedException message.The detailed message and structured error object improve clarity. This change is approved.
178-181
: Enhanced NotFoundException message.The detailed message and structured error object improve clarity. This change is approved.
backend/src/workspace-documents/workspace-documents.service.ts (5)
29-33
: Enhanced NotFoundException message.The detailed message and structured error object improve clarity. This change is approved.
59-63
: Enhanced NotFoundException message.The detailed message and structured error object improve clarity. This change is approved.
129-133
: Enhanced NotFoundException message.The detailed message and structured error object improve clarity. This change is approved.
161-165
: Enhanced NotFoundException message.The detailed message and structured error object improve clarity. This change is approved.
122-127
: Improved readability and maintainability.Storing the return value in a variable before returning improves readability and maintainability. This change is approved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have few questions.
Q1)
In constructor of NestJS HTTP error, I found that we can modify JSON response body by overriding objectOrError
.
Should we use second parameter descriptionOrOptions
?
constructor(objectOrError?: string | object | any, descriptionOrOptions?: string | HttpExceptionOptions);
By default, the JSON response body contains two properties:
statusCode
: this will be the value 404.message
: the string'Not Found'
by default; override this by supplying a string in theobjectOrError
parameter.
Q2)
It seems that the cause
field in descriptionOrOptions
are all new Error()
. Should we pass the field?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (9)
- backend/src/auth/jwt.guard.ts (2 hunks)
- backend/src/documents/documents.service.ts (1 hunks)
- backend/src/files/files.service.ts (2 hunks)
- backend/src/intelligence/intelligence.service.ts (1 hunks)
- backend/src/users/users.service.ts (1 hunks)
- backend/src/workspace-documents/workspace-documents.service.ts (4 hunks)
- backend/src/workspace-users/workspace-users.service.ts (1 hunks)
- backend/src/workspaces/workspaces.service.ts (3 hunks)
- frontend/src/hooks/useErrorHandler.ts (1 hunks)
Files skipped from review as they are similar to previous changes (9)
- backend/src/auth/jwt.guard.ts
- backend/src/documents/documents.service.ts
- backend/src/files/files.service.ts
- backend/src/intelligence/intelligence.service.ts
- backend/src/users/users.service.ts
- backend/src/workspace-documents/workspace-documents.service.ts
- backend/src/workspace-users/workspace-users.service.ts
- backend/src/workspaces/workspaces.service.ts
- frontend/src/hooks/useErrorHandler.ts
Thank you asking, @devleejb A1) A2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- frontend/src/hooks/useErrorHandler.ts (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- frontend/src/hooks/useErrorHandler.ts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution.
* Add detail error descriptions * Fix exception occurrence * Update JwtAuthGuard to handle token expiration and invalid token errors * Update useErrorHandler to handle custom error responses * Update error handling and exception messages * Update error handler to handle custom error response * Update JwtAuthGuard to handle exception with handleRequest * Remove console.error in useErrorHandler
What this PR does / why we need it:
The currently implemented error exceptions don't have a detailed reason for the error, so users can't figure out why the error occurred. To solve this problem, I've added a detailed reason for each error exception and JWT AuthGuard. I've also modified the snackbar menu on the frontend to output the detailed reason.
Before modification
After modification
Which issue(s) this PR fixes:
Fixes #196
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist:
Summary by CodeRabbit
New Features
CustomError
interface in the frontend for better error handling.Bug Fixes
Documentation