More error handling around config saving

This commit is contained in:
Peter Clement 2021-07-16 14:07:48 +01:00
parent 87eea284ab
commit 8297d058b5
2 changed files with 29 additions and 16 deletions

View File

@ -92,6 +92,15 @@
const providers = { google, oidc } const providers = { google, oidc }
// Create a flag so that it will only try to save completed forms // Create a flag so that it will only try to save completed forms
$: trySaveGoogle =
providers.google?.config.clientID ||
providers.google?.config.clientSecret ||
providers.google?.config.callbackURL
$: trySaveOidc =
providers.oidc?.config?.configs[0].configUrl ||
providers.oidc?.config?.configs[0].clientID ||
providers.oidc?.config?.configs[0].clientSecret
$: googleComplete = $: googleComplete =
providers.google?.config.clientID && providers.google?.config.clientID &&
providers.google?.config.clientSecret && providers.google?.config.clientSecret &&
@ -130,23 +139,27 @@
element.config.configs.forEach(config => { element.config.configs.forEach(config => {
!config.uuid && (config.uuid = uuid()) !config.uuid && (config.uuid = uuid())
}) })
if (oidcComplete) { if (trySaveOidc) {
calls.push(api.post(`/api/admin/configs`, element)) if (!oidcComplete) {
completed.push(ConfigTypes.OIDC) notifications.error(
} else { `Please fill in all required ${ConfigTypes.OIDC} fields`
notifications.error( )
`Please fill in all required ${ConfigTypes.OIDC} fields` } else {
) calls.push(api.post(`/api/admin/configs`, element))
completed.push(ConfigTypes.OIDC)
}
} }
} }
if (element.type === ConfigTypes.Google) { if (element.type === ConfigTypes.Google) {
if (googleComplete) { if (trySaveGoogle) {
calls.push(api.post(`/api/admin/configs`, element)) if (!googleComplete) {
completed.push(ConfigTypes.OIDC) notifications.error(
} else { `Please fill in all required ${ConfigTypes.Google} fields`
notifications.error( )
`Please fill in all required ${ConfigTypes.Google} fields` } else {
) calls.push(api.post(`/api/admin/configs`, element))
completed.push(ConfigTypes.Google)
}
} }
} }
}) })
@ -167,7 +180,7 @@
notifications.success(`Settings saved.`) notifications.success(`Settings saved.`)
}) })
.catch(err => { .catch(err => {
notifications.error(`Failed to update OAuth settings. ${err}`) notifications.error(`Failed to update auth settings. ${err}`)
throw new Error(err.message) throw new Error(err.message)
}) })
} }

View File

@ -17,7 +17,7 @@ export function createOrganisationStore() {
async function init() { async function init() {
const res = await api.get(`/api/admin/configs/public`) const res = await api.get(`/api/admin/configs/public`)
const json = await res.json() const json = await res.json()
console.log(json)
if (json.status === 400) { if (json.status === 400) {
set(DEFAULT_CONFIG) set(DEFAULT_CONFIG)
} else { } else {