Skip to content

Commit b9f95e9

Browse files
perf: Improve Form Validation on Third-Party Authentication Platforms
1 parent 7f6faca commit b9f95e9

File tree

4 files changed

+44
-16
lines changed

4 files changed

+44
-16
lines changed

frontend/src/views/system/authentication/CasEditor.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ const submitForm = async (formEl: FormInstance | undefined) => {
128128
name: 'cas',
129129
}
130130
const method = id.value
131-
? request.put('/system/authentication', data)
132-
: request.post('/system/authentication', data)
131+
? request.put('/system/authentication', data, { requestOptions: { silent: true } })
132+
: request.post('/system/authentication', data, { requestOptions: { silent: true } })
133133
showLoading()
134134
method
135135
.then((res) => {
@@ -138,9 +138,16 @@ const submitForm = async (formEl: FormInstance | undefined) => {
138138
emits('saved')
139139
reset()
140140
}
141-
closeLoading()
142141
})
143-
.catch(() => {
142+
.catch((e: any) => {
143+
if (
144+
e.message?.startsWith('sqlbot_authentication_connect_error') ||
145+
e.response?.data?.startsWith('sqlbot_authentication_connect_error')
146+
) {
147+
ElMessage.error(t('ds.connection_failed'))
148+
}
149+
})
150+
.finally(() => {
144151
closeLoading()
145152
})
146153
}

frontend/src/views/system/authentication/LdapEditor.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ const submitForm = async (formEl: FormInstance | undefined) => {
119119
name: 'ldap',
120120
}
121121
const method = id.value
122-
? request.put('/system/authentication', data)
123-
: request.post('/system/authentication', data)
122+
? request.put('/system/authentication', data, { requestOptions: { silent: true } })
123+
: request.post('/system/authentication', data, { requestOptions: { silent: true } })
124124
showLoading()
125125
method
126126
.then((res) => {
@@ -129,9 +129,16 @@ const submitForm = async (formEl: FormInstance | undefined) => {
129129
emits('saved')
130130
reset()
131131
}
132-
closeLoading()
133132
})
134-
.catch(() => {
133+
.catch((e: any) => {
134+
if (
135+
e.message?.startsWith('sqlbot_authentication_connect_error') ||
136+
e.response?.data?.startsWith('sqlbot_authentication_connect_error')
137+
) {
138+
ElMessage.error(t('ds.connection_failed'))
139+
}
140+
})
141+
.finally(() => {
135142
closeLoading()
136143
})
137144
}

frontend/src/views/system/authentication/Oauth2Editor.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ const submitForm = async (formEl: FormInstance | undefined) => {
232232
name: 'oauth2',
233233
}
234234
const method = id.value
235-
? request.put('/system/authentication', data)
236-
: request.post('/system/authentication', data)
235+
? request.put('/system/authentication', data, { requestOptions: { silent: true } })
236+
: request.post('/system/authentication', data, { requestOptions: { silent: true } })
237237
showLoading()
238238
method
239239
.then((res) => {
@@ -242,9 +242,16 @@ const submitForm = async (formEl: FormInstance | undefined) => {
242242
emits('saved')
243243
reset()
244244
}
245-
closeLoading()
246245
})
247-
.catch(() => {
246+
.catch((e: any) => {
247+
if (
248+
e.message?.startsWith('sqlbot_authentication_connect_error') ||
249+
e.response?.data?.startsWith('sqlbot_authentication_connect_error')
250+
) {
251+
ElMessage.error(t('ds.connection_failed'))
252+
}
253+
})
254+
.finally(() => {
248255
closeLoading()
249256
})
250257
}

frontend/src/views/system/authentication/OidcEditor.vue

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ const submitForm = async (formEl: FormInstance | undefined) => {
174174
name: 'oidc',
175175
}
176176
const method = id.value
177-
? request.put('/system/authentication', data)
178-
: request.post('/system/authentication', data)
177+
? request.put('/system/authentication', data, { requestOptions: { silent: true } })
178+
: request.post('/system/authentication', data, { requestOptions: { silent: true } })
179179
showLoading()
180180
method
181181
.then((res) => {
@@ -184,9 +184,16 @@ const submitForm = async (formEl: FormInstance | undefined) => {
184184
emits('saved')
185185
reset()
186186
}
187-
closeLoading()
188187
})
189-
.catch(() => {
188+
.catch((e: any) => {
189+
if (
190+
e.message?.startsWith('sqlbot_authentication_connect_error') ||
191+
e.response?.data?.startsWith('sqlbot_authentication_connect_error')
192+
) {
193+
ElMessage.error(t('ds.connection_failed'))
194+
}
195+
})
196+
.finally(() => {
190197
closeLoading()
191198
})
192199
}

0 commit comments

Comments
 (0)