-
Notifications
You must be signed in to change notification settings - Fork 421
RI-7778 Add proper error messages for invalid cloud database endpoints #5266
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
base: main
Are you sure you want to change the base?
RI-7778 Add proper error messages for invalid cloud database endpoints #5266
Conversation
Validate publicEndpoint before calling split() to prevent null reference errors. Return user-friendly error messages instead of raw JavaScript errors. References: #RI-7778
- Introduced a section on custom exceptions, emphasizing their benefits for consistent error handling. - Added examples for creating custom exceptions in TypeScript. - Included a new section on parameterized tests using `it.each`, highlighting its advantages for maintainability and readability.
Code Coverage - Integration Tests
|
Code Coverage - Backend unit tests
Test suite run success2967 tests passing in 287 suites. Report generated by 🧪jest coverage report action from c386bae |
| publicEndpoint: string | null | undefined, | ||
| ): boolean { | ||
| return ( | ||
| !!publicEndpoint && !!publicEndpoint.trim() && publicEndpoint.includes(':') |
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.
is this the best way to check it or there can be a regex with more rules?
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.
Actually, all we care about is whether there is a value for the publicEndpoint, but since we split it later in the code by :, the AI considered it makes sense to check it here as well.
For sure, we can make the validation smarter, but I don't have the requirements for it, so here we're just improvising.
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 would say we just need to check if we have not empty string. It should be enough.
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.
Ok, done. I have simplified the validation so we check only whether the publicEndpoint is present 👍
| message, | ||
| statusCode: HttpStatus.BAD_REQUEST, | ||
| error: 'FeatureInvalid', | ||
| errorCode: CustomErrorCodes.FeatureInvalid, |
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.
does it make sense to enforce that these fields are provided for all exceptions (e.g. extract and implement a common interface)? Currently it's typed as Record<string, any> and if we have a common interface, we can have more predictive api responses
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.
This is the current pattern, so I just plugged into it.
What you suggest sounds reasonable to me, but I believe @ArtemHoruzhenko can advise on architectural changes like that.
| CLOUD_DATABASE_IMPORT_FORBIDDEN: | ||
| 'Adding your Redis Cloud database to Redis Insight is disabled due to a setting restricting database connection management.', | ||
| CLOUD_DATABASE_ENDPOINT_INVALID: | ||
| 'Database endpoint is not available or not fully provisioned yet.', |
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.
Can we change the message?
I would say that we must say something like: "Public endpoint is disabled for this database"
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.
Of course, we can put whatever we want.
| publicEndpoint: string | null | undefined, | ||
| ): boolean { | ||
| return ( | ||
| !!publicEndpoint && !!publicEndpoint.trim() && publicEndpoint.includes(':') |
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 would say we just need to check if we have not empty string. It should be enough.
…point re #RI-7778
What
Fixes the issue where users see raw JavaScript errors like "Cannot read properties of null (reading 'split')" when adding cloud databases with invalid endpoints. Now returns user-friendly error messages instead.
Testing
Prerequisites: You need a Redis Cloud account with a PRO-tier subscription database with a disabled public endpoint.
You'll be redirected to the "Redis Enterprise Databases Added" screen, once the import is done. Observe the errors in the Results column.
Note
Introduce
CloudDatabaseEndpointInvaliderror (code11_116) and use it to validate missingpublicEndpointacross cloud import/create flows, with tests and docs updates.CloudDatabaseEndpointInvalidExceptionwith messageCLOUD_DATABASE_ENDPOINT_INVALIDand codeCustomErrorCodes.CloudDatabaseEndpointInvalid.publicEndpointincloud-autodiscovery.serviceand return structured failure when missing.create-free-database.cloud-jobandimport-free-database.cloud-jobwhenpublicEndpointis absent.11_116inapi/src/constants/custom-error-codes.ts; add message inapi/src/constants/error-messages.ts.cloud/job/exceptions/index.ts.it.each) for null/undefinedpublicEndpointincloud-autodiscovery.service.spec.ts.CloudDatabaseEndpointInvalid = 11_116inui/src/constants/customErrorCodes.ts.it.eachusage guidance.Written by Cursor Bugbot for commit c386bae. This will update automatically on new commits. Configure here.