-
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
Changes from 2 commits
dd72366
d411e7c
c386bae
90f362c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,6 +144,8 @@ export default { | |
| CLOUD_DATABASE_ALREADY_EXISTS_FREE: 'Free database already exists', | ||
| 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.', | ||
|
||
| CLOUD_PLAN_NOT_FOUND_FREE: 'Unable to find free cloud plan', | ||
| CLOUD_SUBSCRIPTION_ALREADY_EXISTS_FREE: 'Free subscription already exists', | ||
| COMMON_DEFAULT_IMPORT_ERROR: 'Unable to import default data', | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,14 @@ export function convertRedisCloudModuleName(name: string): string { | |
| return REDIS_CLOUD_MODULES_NAMES[name] ?? name; | ||
| } | ||
|
|
||
| export function isValidCloudDatabaseEndpoint( | ||
| publicEndpoint: string | null | undefined, | ||
| ): boolean { | ||
| return ( | ||
| !!publicEndpoint && !!publicEndpoint.trim() && publicEndpoint.includes(':') | ||
|
||
| ); | ||
| } | ||
|
|
||
| export const parseCloudDatabaseCapiResponse = ( | ||
| database: ICloudCapiDatabase, | ||
| tags: ICloudCapiDatabaseTag[], | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { | ||
| HttpException, | ||
| HttpExceptionOptions, | ||
| HttpStatus, | ||
| } from '@nestjs/common'; | ||
| import ERROR_MESSAGES from 'src/constants/error-messages'; | ||
| import { CustomErrorCodes } from 'src/constants'; | ||
|
|
||
| export class CloudDatabaseEndpointInvalidException extends HttpException { | ||
| constructor( | ||
| message = ERROR_MESSAGES.CLOUD_DATABASE_ENDPOINT_INVALID, | ||
| options?: HttpExceptionOptions, | ||
| ) { | ||
| const response = { | ||
| message, | ||
| statusCode: HttpStatus.BAD_REQUEST, | ||
| error: 'CloudDatabaseEndpointInvalid', | ||
| errorCode: CustomErrorCodes.CloudDatabaseEndpointInvalid, | ||
| }; | ||
|
|
||
| super(response, response.statusCode, options); | ||
| } | ||
| } |
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 responsesThere 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.