diff --git a/index.js b/index.js index d44530f3e0f040674789ab4d76352bd21c7eb7da..1513bb78030d8c16bf46dce98d0e1a852ea90ddc 100644 --- a/index.js +++ b/index.js @@ -85,7 +85,12 @@ async function start(fields, cozyParameters) { ) } - const { pce, email, firstname, lastname, postalCode } = fields + let { pce, email, firstname, lastname, postalCode } = fields + + if (!pce && fields?.oauth_callback_results?.pce) { + pce = fields.oauth_callback_results.pce + log('info', `OAuth callback result found, using pce ${pce}`) + } const transaction = Sentry.startTransaction({ op: 'konnector', @@ -107,6 +112,11 @@ async function start(fields, cozyParameters) { const boUrlGRDF = new URL('/api/grdf', boBaseUrl).href try { + if (!pce) { + log('error', 'No PCE found') + throw errors.VENDOR_DOWN + } + log('info', `using PCE: ${pce}`) const { access_token } = await getAuthToken(grdfId, grdfSecret) const consents = await getConsents(access_token, pce) const noValidConsent = await handleConsents(consents, boUrlGRDF, boToken)