Skip to content

Commit

Permalink
Merge pull request #806 from Badsender-com/develop
Browse files Browse the repository at this point in the history
Update develop-clever with develop
  • Loading branch information
FlorianGille committed Jun 4, 2024
2 parents 1ad7385 + b992967 commit 56d29bc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
13 changes: 12 additions & 1 deletion packages/editor/src/js/vue/components/esp/esp-send-mail.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ const EspComponent = Vue.component('EspForm', {
.catch((error) => {
// handle error
console.log(error);

/*
If the campaign for this profile should exist but was not found on DSC,
Then it was probably deleted on DSC's side.
So we allow the user to create a new one
*/
if(error.response.status === 404) {
this.type = SEND_MODE.CREATION;
this.fetchProfileData(message);
return;
}

this.vm.notifier.error(this.vm.t('error-server'));
})
.finally(() => {
Expand Down Expand Up @@ -170,7 +182,6 @@ const EspComponent = Vue.component('EspForm', {
campaignMailName: data?.campaignMailName,
subject: data?.subject,
planification: data?.planification,
controlMail: data?.controlMail,
typeCampagne: data?.typeCampagne,
},
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const DscComponent = Vue.component('DscComponent', {
campaignMailName: '',
planification: '',
subject: '',
controlMail: '',
type: ESP_TYPE.DSC,
},
style: styleHelper,
Expand All @@ -47,12 +46,10 @@ const DscComponent = Vue.component('DscComponent', {
id,
additionalApiData: { planification, typeCampagne } = {},
} = this.fetchedProfile;
const controlMail = this.vm.currentUser().email;
this.profile = {
campaignMailName: campaignMailName ?? '',
planification: planification ?? '',
subject: subject ?? '',
controlMail,
typeCampagne: typeCampagne ?? '',
id: id ?? '',
};
Expand Down
15 changes: 14 additions & 1 deletion packages/server/esp/dsc/dscProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ const mailingService = require('../../mailing/mailing.service.js');
const ERROR_CODES = require('../../constant/error-codes.js');
const config = require('../../node.config.js');
const axios = require('../../config/axios');
const { InternalServerError, Conflict, BadRequest } = require('http-errors');
const {
InternalServerError,
Conflict,
BadRequest,
NotFound,
} = require('http-errors');

class DscProvider {
constructor({ apiKey, ...data }) {
Expand Down Expand Up @@ -98,6 +103,10 @@ class DscProvider {
throw new BadRequest(message);
}

if (status === 409) {
throw new Conflict(message);
}

// Log the error and throw a generic error if it doesn't match specific cases
logger.error('Error in API call:', error);
throw new Error('An error occurred while communicating with the API.');
Expand Down Expand Up @@ -137,6 +146,10 @@ class DscProvider {
} catch (e) {
logger.error({ error: e });

if (e?.status === 404) {
throw new NotFound('Campaign not found on DSC');
}

throw e;
}
}
Expand Down
8 changes: 7 additions & 1 deletion packages/server/profile/profile.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ async function sendEspCampaign({
const { subject, campaignMailName, planification } = espSendingMailData;
const profile = await findOne(profileId);

await checkIfMailAlreadySentToProfile({ profileId, mailingId });
/*
For DSC, creating a new campaign from the same profile is allowed
if the campaign was deleted on DSC's side
*/
if (type !== 'DSC') {
await checkIfMailAlreadySentToProfile({ profileId, mailingId });
}

const {
apiKey,
Expand Down

0 comments on commit 56d29bc

Please sign in to comment.