Skip to content

Commit ff8c8fb

Browse files
#RI-5749 - resolve comments
1 parent 81990f0 commit ff8c8fb

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

redisinsight/ui/src/utils/errors.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { AxiosError } from 'axios'
2-
import { capitalize, clone, isEmpty, isString, isArray, set } from 'lodash'
2+
import { capitalize, isEmpty, isString, isArray, set } from 'lodash'
33
import React from 'react'
44
import { EuiSpacer } from '@elastic/eui'
55
import { CustomErrorCodes } from 'uiSrc/constants'
@@ -12,14 +12,12 @@ export const getRdiValidationMessage = (message: string = '', loc?: string[]): s
1212
if (!loc || !isArray(loc) || loc.length < 2) {
1313
return message
1414
}
15-
const locArr = clone(loc)
16-
locArr.shift()
17-
18-
const field = locArr.pop()
19-
const path = locArr?.join('/')
15+
const [, ...rest] = loc
16+
const field = rest.pop() as string
17+
const path = rest.join('/')
2018
const words = message.split(' ')
2119

22-
words[0] = path ? `${field} in ${path}` : field || ''
20+
words[0] = path ? `${field} in ${path}` : field
2321

2422
return capitalize(words.join(' '))
2523
}
@@ -174,7 +172,7 @@ export const parseCustomError = (err: CustomError | string = DEFAULT_ERROR_MESSA
174172
break
175173

176174
case CustomErrorCodes.RdiValidationError:
177-
const details = err?.details[0] || {}
175+
const details = err?.details?.[0] || {}
178176
title = 'Validation error'
179177
message = getRdiValidationMessage(details.msg, err?.details[0]?.loc)
180178

redisinsight/ui/src/utils/tests/errors.spec.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,16 @@ describe('parseCustomError', () => {
125125
const getRdiValidationMessageTests: Array<[[Maybe<string>, string[]], string]> = [
126126
[[undefined, []], ''],
127127
[['Custom message', []], 'Custom message'],
128-
[['Custom message', ['field']], 'Custom message'],
129-
[['Custom message', ['field', 'field2']], 'Field2 message'],
130-
[['Custom message', ['field', 'field2', 'field3']], 'Field3 in field2 message'],
131-
[['Custom message', ['field', 'field2', 'field3', 'field4']], 'Field4 in field2/field3 message'],
128+
[['Input is required', ['field']], 'Input is required'],
129+
[['Input required', ['body', 'targets']], 'Targets required'],
130+
[
131+
['Input should be \'postgresql\', \'mysql\', \'oracle\', \'cassandra\', \'sqlserver\' or \'redis\'', ['body', 'targets', 'type']],
132+
'Type in targets should be \'postgresql\', \'mysql\', \'oracle\', \'cassandra\', \'sqlserver\' or \'redis\''
133+
],
134+
[
135+
['Input should be a valid integer, unable to parse string as an integer', ['body', 'targets', 'my-redis', 'connection']],
136+
'Connection in targets/my-redis should be a valid integer, unable to parse string as an integer'
137+
],
132138
]
133139

134140
describe('getRdiValidationMessage', () => {

0 commit comments

Comments
 (0)