Skip to content

Commit

Permalink
fix(contribution): track sendInBlue errors in Sentry
Browse files Browse the repository at this point in the history
  • Loading branch information
JalilArfaoui committed Nov 18, 2020
1 parent 2d11de0 commit de7d774
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/app/content/sagas/contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ import { createSubmissionError } from 'app/utils/form';
import sendEmail from 'api/sendInBlue/sendEmail';
import createContributionEmail from 'app/background/services/createContributionEmail';
import { history } from '../store';
import { captureException } from '../../utils/sentry';
import { createCallAndRetry } from '../../sagas/effects/callAndRetry';

const sendEmailAndRetry = createCallAndRetry({
maximumAttempts: 15, // ~ 1 min 45s
onFinalError: () => {
captureException(new Error('Could not send contribution email'));
}
});

export function* submitContributionSaga({
payload: contribution,
meta: { form, resolve, reject }
}: SubmitContributionAction) {
try {
yield call(sendEmail, createContributionEmail(contribution));
yield sendEmailAndRetry(sendEmail, createContributionEmail(contribution));

yield put(contributionSubmitted(contribution));

Expand Down
11 changes: 10 additions & 1 deletion src/app/content/sagas/question.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@ import { createSubmissionError } from 'app/utils/form';
import sendEmail from 'api/sendInBlue/sendEmail';
import createQuestionEmail from 'app/background/services/createQuestionEmail';
import { history } from '../store';
import { createCallAndRetry } from '../../sagas/effects/callAndRetry';
import { captureException } from '../../utils/sentry';

const sendEmailAndRetry = createCallAndRetry({
maximumAttempts: 15, // ~ 1 min 45s
onFinalError: () => {
captureException(new Error('Could not send question email'));
}
});

export function* submitQuestionSaga({
payload: question,
meta: { form, resolve, reject }
}: SubmitQuestionAction) {
try {
yield call(sendEmail, createQuestionEmail(question));
yield sendEmailAndRetry(sendEmail, createQuestionEmail(question));

yield put(questionSubmitted(question));

Expand Down
6 changes: 6 additions & 0 deletions src/app/sagas/effects/callAndRetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Options = {
maximumAttempts: number;
maximumRetryDelayInMinutes: number;
onError?: OnErrorCallback;
onFinalError?: OnErrorCallback;
};

const defaultOptions: Options = {
Expand Down Expand Up @@ -49,6 +50,11 @@ export const createCallAndRetry = (options: Partial<Options>) =>
attemptNumber + 1,
...args
);
} else {
if ('onFinalError' in o && o.onFinalError) {
yield call(o.onFinalError, e, attemptNumber);
}
throw e;
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/sagas/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { BaseAction, ErrorAction } from '../actions';
import { Level } from '../utils/Logger';

export function* handleErrorSaga({
type,
payload: error,
meta: { severity }
}: ErrorAction): SagaIterator {
if (severity >= Level.ERROR) {
captureException(error);
} else {
captureMessage(error.message, severityToSentry[severity]);
captureMessage(error?.message || type, severityToSentry[severity]);
}
}

Expand Down

0 comments on commit de7d774

Please sign in to comment.