Skip to content

Commit

Permalink
Merge pull request #803 from Badsender-com/staging
Browse files Browse the repository at this point in the history
Release production
  • Loading branch information
FlorianGille committed May 21, 2024
2 parents 2d26812 + 2ee18dd commit db75fe3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
12 changes: 12 additions & 0 deletions 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
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 @@ -85,6 +90,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 @@ -124,6 +133,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 db75fe3

Please sign in to comment.