Better error handling around config saving

This commit is contained in:
Peter Clement 2021-07-16 10:51:58 +01:00
parent f1d8b5516e
commit 2afb6ffe2d
1 changed files with 36 additions and 20 deletions

View File

@ -123,37 +123,53 @@
// only if the user has provided an image, upload it. // only if the user has provided an image, upload it.
image && uploadLogo(image) image && uploadLogo(image)
let calls = [] let calls = []
let completed = []
docs.forEach(element => { docs.forEach(element => {
if (element.type === ConfigTypes.OIDC) { if (element.type === ConfigTypes.OIDC) {
//Add a UUID here so each config is distinguishable when it arrives at the login page. //Add a UUID here so each config is distinguishable when it arrives at the login page.
element.config.configs.forEach(config => { element.config.configs.forEach(config => {
!config.uuid && (config.uuid = uuid()) !config.uuid && (config.uuid = uuid())
}) })
oidcComplete && calls.push(api.post(`/api/admin/configs`, element)) if (oidcComplete) {
calls.push(api.post(`/api/admin/configs`, element))
completed.push(ConfigTypes.OIDC)
} else {
notifications.error(
`Please fill in all required ${ConfigTypes.OIDC} fields`
)
}
} }
if (element.type === ConfigTypes.Google) { if (element.type === ConfigTypes.Google) {
googleComplete && calls.push(api.post(`/api/admin/configs`, element)) if (googleComplete) {
calls.push(api.post(`/api/admin/configs`, element))
completed.push(ConfigTypes.OIDC)
} else {
notifications.error(
`Please fill in all required ${ConfigTypes.Google} fields`
)
}
} }
}) })
Promise.all(calls) calls.length &&
.then(responses => { Promise.all(calls)
return Promise.all( .then(responses => {
responses.map(response => { return Promise.all(
return response.json() responses.map(response => {
}) return response.json()
) })
}) )
.then(data => { })
data.forEach(res => { .then(data => {
providers[res.type]._rev = res._rev data.forEach(res => {
providers[res.type]._id = res._id providers[res.type]._rev = res._rev
providers[res.type]._id = res._id
})
notifications.success(`Settings saved.`)
})
.catch(err => {
notifications.error(`Failed to update OAuth settings. ${err}`)
throw new Error(err.message)
}) })
notifications.success(`Settings saved.`)
})
.catch(err => {
notifications.error(`Failed to update OAuth settings. ${err}`)
throw new Error(err.message)
})
} }
onMount(async () => { onMount(async () => {