Skip to content

Commit

Permalink
fix: remonte erreur addresse de destination invalide du back + interp…
Browse files Browse the repository at this point in the history
…rete sur le front
  • Loading branch information
Shamzic committed Oct 8, 2024
1 parent 93635d6 commit 7ee06de
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 19 deletions.
29 changes: 18 additions & 11 deletions backend/controllers/followups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,26 @@ export function followup(

async function sendFollowupNotifications(followup: Followup, res: Response) {
const { email, phone } = followup
if (phone) {
if (
phoneNumberValidation(phone, config.smsService.internationalDiallingCodes)
) {
await sendSimulationResultsSms(followup)
} else {
return res.status(422).send("Unsupported phone number format")
try {
if (phone) {
if (
phoneNumberValidation(
phone,
config.smsService.internationalDiallingCodes
)
) {
await sendSimulationResultsSms(followup)
} else {
return res.status(422).send("Unsupported phone number format")
}
}
if (email) {
await sendSimulationResultsEmail(followup)
}
return res.send({ result: "OK" })
} catch (error: any) {
return res.status(500).send(error.message)
}
if (email) {
await sendSimulationResultsEmail(followup)
}
return res.send({ result: "OK" })
}

async function createSimulationRecapUrl(req: Request, res: Response) {
Expand Down
11 changes: 7 additions & 4 deletions backend/lib/messaging/sms/sms-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ export async function sendSimulationResultsSms(
followup.smsSentAt = dayjs().toDate()
followup.smsMessageId = data.messageIds[0]
return await followup.save()
} catch (err) {
Sentry.captureException(err)
followup.smsError = JSON.stringify(err, null, 2)
throw err
} catch (error: any) {
// Avoid sending invalid destination address error to sentry
if (!error?.message?.includes("Invalid destination address")) {
Sentry.captureException(error)
}
followup.smsError = JSON.stringify(error, null, 2)
throw error
}
}

Expand Down
10 changes: 10 additions & 0 deletions src/components/modals/errors-email-and-sms-modal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ const recapEmailState = computed(() => store.recapEmailState)
}}
</p>
</div>
<div
v-if="recapPhoneState === 'invalid-address'"
class="fr-alert fr-alert--error"
>
<p>
Une erreur s'est produite dans l'envoi du récapitulatif par SMS :
l'adresse de destination est invalide. Veuillez réessayer avec un
numéro valide ou utiliser l'envoi par email.
</p>
</div>
<div
v-if="recapPhoneState === 'ok' && recapEmailState === 'ok'"
class="fr-alert fr-alert--success"
Expand Down
10 changes: 6 additions & 4 deletions src/components/recap-email-and-sms-form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ const sendRecap = async (surveyOptin) => {
ABTestingService.getValues().CTA_EmailRecontact
)
}
} catch (error) {
console.error(error)
Sentry.captureException(error)
} catch (error: any) {
if (!error?.response?.data?.includes("Invalid destination address")) {
Sentry.captureException(error)
} else {
store.setFormRecapPhoneState("invalid-address")
}
}
}
Expand Down Expand Up @@ -181,7 +184,6 @@ const sendRecapByEmail = async (surveyOptin) => {
store.setModalState(undefined)
await postFollowup(surveyOptin, emailValue.value)
} catch (error) {
Sentry.captureException(error)
store.setFormRecapEmailState("error")
throw error
}
Expand Down

0 comments on commit 7ee06de

Please sign in to comment.