Skip to content

Commit

Permalink
add try catch if call to grist fails (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitSerrano authored Oct 11, 2024
2 parents b9eb021 + ed6f266 commit 393b962
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 44 deletions.
2 changes: 1 addition & 1 deletion lib/format.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module.exports.extractEmailDomain = function(email) {

// Vérification si l'adresse email est valide
if (!emailRegex.test(email)) {
throw new Error("Adresse email invalide");
return undefined
}

// Extraction du domaine avec un split
Expand Down
40 changes: 0 additions & 40 deletions lib/format.test.js

This file was deleted.

6 changes: 3 additions & 3 deletions lib/oidcAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ module.exports.finishAuth = async (req) => {
try {
const domain = format.extractEmailDomain(email)
const whitelistedDomains = await getWhitelistedDomains()
if(!whitelistedDomains.includes(domain)){
throw new Error(`The domain ${domain} is not whitelisted.`)
if(!domain || !whitelistedDomains.includes(domain)){
console.error(`The domain ${domain} is not whitelisted.`)
return { error: `L'adresse e-mail ${email} n'est pas autorisée à utiliser ce service. Si vous êtes agent de l'État, contactez-nous à [email protected]` }
}
} catch(e){
console.error(`error when validating email ${email}`,e)
return { error: `L'adresse e-mail ${email} n'est pas autorisée à utiliser ce service. Si vous êtes agent de l'État, contactez-nous à [email protected]` }
}

const user = {id_token: tokenSet.id_token, state: request.state}
Expand Down

0 comments on commit 393b962

Please sign in to comment.