Skip to content

Commit 7cf0c36

Browse files
#RI-5749 - cover 422 error
1 parent b44a257 commit 7cf0c36

File tree

13 files changed

+108
-20
lines changed

13 files changed

+108
-20
lines changed

redisinsight/api/src/constants/custom-error-codes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ export enum CustomErrorCodes {
5757
RdiDeployPipelineFailure = 11_401,
5858
RdiUnauthorized = 11_402,
5959
RdiInternalServerError = 11_403,
60-
60+
RdiValidationError = 11_404,
6161
}

redisinsight/api/src/constants/error-messages.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,5 @@ export default {
110110

111111
RDI_DEPLOY_PIPELINE_FAILURE: 'Failed to deploy pipeline',
112112
RDI_TIMEOUT_ERROR: 'Encountered a timeout error while attempting to retrieve data',
113+
RDI_VALIDATION_ERROR: 'Validation error',
113114
};

redisinsight/api/src/modules/rdi/exceptions/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './rdi-pipiline.error.handler';
33
export * from './rdi-pipeline.internal-server-error.exception';
44
export * from './rdi-pipeline.not-found.exception';
55
export * from './rdi-pipeline.unauthorized.exception';
6+
export * from './rdi-pipeline.validation.exception';
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { HttpException, HttpExceptionOptions, HttpStatus } from '@nestjs/common';
2+
import { CustomErrorCodes } from 'src/constants';
3+
import ERROR_MESSAGES from 'src/constants/error-messages';
4+
5+
export class RdiPipelineValidationException extends HttpException {
6+
constructor(
7+
message = ERROR_MESSAGES.RDI_VALIDATION_ERROR,
8+
options?: HttpExceptionOptions & { details?: unknown },
9+
) {
10+
const response = {
11+
message,
12+
statusCode: HttpStatus.UNPROCESSABLE_ENTITY,
13+
error: 'RdiValidationError',
14+
errorCode: CustomErrorCodes.RdiValidationError,
15+
details: options,
16+
};
17+
18+
super(response, response.statusCode, options);
19+
}
20+
}

redisinsight/api/src/modules/rdi/exceptions/rdi-pipiline.error.handler.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AxiosError } from 'axios';
22
import { HttpException } from '@nestjs/common';
33
import {
44
RdiPipelineInternalServerErrorException,
5-
RdiPipelineUnauthorizedException, RdiPipelineNotFoundException,
5+
RdiPipelineUnauthorizedException, RdiPipelineNotFoundException, RdiPipelineValidationException,
66
} from 'src/modules/rdi/exceptions';
77

88
export const wrapRdiPipelineError = (error: AxiosError<any>, message?: string): HttpException => {
@@ -11,11 +11,14 @@ export const wrapRdiPipelineError = (error: AxiosError<any>, message?: string):
1111
}
1212

1313
const { response } = error;
14+
1415
if (response) {
1516
const errorOptions = response?.data?.detail;
1617
switch (response?.status) {
1718
case 401:
1819
return new RdiPipelineUnauthorizedException(message, errorOptions);
20+
case 422:
21+
return new RdiPipelineValidationException(message, errorOptions);
1922
default:
2023
return new RdiPipelineNotFoundException(message, errorOptions);
2124
}

redisinsight/ui/src/components/monaco-editor/components/monaco-yaml/MonacoYaml.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react'
1+
import React, { useEffect } from 'react'
22
import { isNull } from 'lodash'
33

44
import { CommonProps } from 'uiSrc/components/monaco-editor/MonacoEditor'
@@ -23,15 +23,22 @@ const MonacoYaml = (props: Props) => {
2323
...rest
2424
} = props
2525

26-
// insert schema work only before monaco will be rendered
27-
if (isNull(schema)) {
28-
return null
29-
}
26+
useEffect(() => {
27+
if (!isNull(schema)) {
28+
monacoYamlModel?.update({
29+
schemas: [{
30+
schema,
31+
uri,
32+
fileMatch: [fileMatch],
33+
}],
34+
})
35+
}
36+
}, [schema, uri, fileMatch])
3037

3138
const editorWillMount = () => {
3239
monacoYamlModel?.update({
3340
schemas: [{
34-
schema,
41+
schema: schema || {},
3542
uri,
3643
fileMatch: [fileMatch],
3744
}],

redisinsight/ui/src/constants/customErrorCodes.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export enum CustomErrorCodes {
5454

5555
GeneralAiUnexpectedError = 11_391,
5656

57-
// RDI errors [11300, 11499]
58-
RdiDeployPipelineFailure = 11_301,
57+
// RDI errors [11400, 11499]
58+
RdiDeployPipelineFailure = 11_401,
59+
RdiValidationError = 11_404,
5960
}

redisinsight/ui/src/slices/interfaces/app.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { GetServerInfoResponse } from 'apiSrc/modules/server/dto/server.dto'
66
import { RedisString as RedisStringAPI } from 'apiSrc/common/constants/redis-string'
77

88
export interface CustomError {
9+
details?: any;
910
error: string
1011
message: string
1112
statusCode: number

redisinsight/ui/src/slices/rdi/dryRun.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit'
22
import { AxiosError } from 'axios'
33
import { apiService, } from 'uiSrc/services'
44
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
5-
import { getApiErrorMessage, isStatusSuccessful } from 'uiSrc/utils'
6-
import { IDryRunJobResults, IStateRdiDryRunJob } from 'uiSrc/slices/interfaces'
5+
import { getApiErrorMessage, getAxiosError, isStatusSuccessful } from 'uiSrc/utils'
6+
import { EnhancedAxiosError, IDryRunJobResults, IStateRdiDryRunJob } from 'uiSrc/slices/interfaces'
77

88
import { AppDispatch, RootState } from '../store'
99

@@ -73,8 +73,10 @@ export function rdiDryRunJob(
7373
}
7474
} catch (_err) {
7575
const error = _err as AxiosError
76+
const parsedError = getAxiosError(error as EnhancedAxiosError)
7677
const errorMessage = getApiErrorMessage(error)
77-
dispatch(addErrorNotification(error))
78+
79+
dispatch(addErrorNotification(parsedError))
7880
dispatch(dryRunJobFailure(errorMessage))
7981
onFailAction?.()
8082
}

redisinsight/ui/src/slices/rdi/testConnections.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import { apiService, } from 'uiSrc/services'
44
import { addErrorNotification } from 'uiSrc/slices/app/notifications'
55
import {
66
getApiErrorMessage,
7+
getAxiosError,
78
getRdiUrl,
89
isStatusSuccessful,
910
Maybe,
1011
Nullable,
1112
transformConnectionResults
1213
} from 'uiSrc/utils'
1314
import {
15+
EnhancedAxiosError,
1416
IStateRdiTestConnections,
1517
TestConnectionsResponse,
1618
TransformResult
@@ -94,8 +96,10 @@ export function testConnectionsAction(
9496
} catch (_err) {
9597
if (!axios.isCancel(_err)) {
9698
const error = _err as AxiosError
99+
const parsedError = getAxiosError(error as EnhancedAxiosError)
97100
const errorMessage = getApiErrorMessage(error)
98-
dispatch(addErrorNotification(error))
101+
102+
dispatch(addErrorNotification(parsedError))
99103
dispatch(testConnectionsFailure(errorMessage))
100104
onFailAction?.()
101105
} else {

0 commit comments

Comments
 (0)