Skip to content
Snippets Groups Projects
Commit 2df90c7c authored by Bastien DUMONT's avatar Bastien DUMONT :angel:
Browse files

add service ID

parent 82c80082
No related branches found
No related tags found
1 merge request!54fix: throw vendor down when request is rejected
Pipeline #93833 passed
......@@ -46,7 +46,11 @@ async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) {
throw new Error(errors.CAPTCHA_RESOLUTION_FAILED)
})
catchRequestReject(response.body)
try {
catchRequestReject(response.body)
} catch (error) {
throw new Error(errors.CAPTCHA_RESOLUTION_FAILED)
}
const parsedReply = await xml2js.parseStringPromise(response.body, {
tagNameProcessors: [parseTags],
......@@ -82,7 +86,7 @@ async function verifyContract(url, apiAuthKey, appLogin, contractId, pointId) {
section: 'verifyContract',
},
})
if (parsedReply.Envelope.Body.Fault) {
if (parsedReply?.Envelope?.Body?.Fault) {
log(
'error',
`Enedis issue ${parsedReply.Envelope.Body.Fault.detail.erreur.resultat.$.code}: ${parsedReply.Envelope.Body.Fault.faultstring}`
......
const { log, errors } = require('cozy-konnector-libs')
const { log } = require('cozy-konnector-libs')
/**
* Throw a VENDOR_DOWN error if the response contains a "Request Rejected"
* Throw an error if the response contains a "Request Rejected"
* Enedis might send a 429 status but the F5 always transform it to a 200
* @param {string} response
* @example <html><head><title>Request Rejected</title></head>
......@@ -9,9 +9,11 @@ const { log, errors } = require('cozy-konnector-libs')
*/
function catchRequestReject(response) {
if (response.includes('Request Rejected')) {
const supportID = response.replace(/\D/g, '')
log('debug', response.slice(0, 100))
log('error', `Support ID : ${supportID}`)
log('error', 'Request Rejected')
throw new Error(errors.VENDOR_DOWN)
throw new Error('Request Rejected')
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment