Skip to content

Commit

Permalink
chore(error-handling): do not treat as error common uses cases
Browse files Browse the repository at this point in the history
A context not triggered happens on pretty much any pages, so shouldn't be an error.
Also when a user does'nt have any notices left display whereas the context was trigger, it's often due to its prefs.
  • Loading branch information
lutangar committed Jul 2, 2019
1 parent 4e4c12e commit cadc9c4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/app/actions/notices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ export const noticesFound = (
}
});

// Context was triggered but they were no notices left to display
export interface NoNoticesDisplayedAction extends TabAction {
type: 'NO_NOTICES_DISPLAYED';
}

export const noNoticesDisplayed = (tab: Tab): NoNoticesDisplayedAction => ({
type: 'NO_NOTICES_DISPLAYED',
meta: {
tab
}
});

export type feedbackType =
| 'dismiss'
| 'undismiss'
Expand Down
13 changes: 13 additions & 0 deletions src/app/actions/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,19 @@ export const contextTriggered = (
meta: { tab }
});

export interface ContextNotTriggeredAction extends TabAction {
type: 'LMEM/CONTEXT_NOT_TRIGGERED';
payload: MatchingContext[];
}
export const contextNotTriggered = (
triggeredContexts: MatchingContext[],
tab: Tab
): ContextNotTriggeredAction => ({
type: 'LMEM/CONTEXT_NOT_TRIGGERED',
payload: triggeredContexts,
meta: { tab }
});

export interface ContextTriggerFailureAction extends TabErrorAction {
type: 'LMEM/CONTEXT_TRIGGER_FAILURE';
}
Expand Down
9 changes: 5 additions & 4 deletions src/app/background/sagas/tab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import {
noticeDisplayed,
contextTriggerFailure,
MatchContextAction,
ContextTriggeredAction
ContextTriggeredAction,
contextNotTriggered
} from 'app/actions/tabs';
import {
noNoticesDisplayed,
noticesFound,
NoticesFoundAction,
noticesUpdated
Expand Down Expand Up @@ -67,7 +69,7 @@ export function* matchContextSaga({ meta: { tab } }: MatchContextAction) {
if (triggeredContexts.length >= 1) {
yield put(contextTriggered(triggeredContexts, tab));
} else {
throw new Error('No contexts triggered');
yield put(contextNotTriggered(triggeredContexts, tab));
}
} catch (e) {
yield put(matchContextFailure(e, tab));
Expand Down Expand Up @@ -107,8 +109,7 @@ export const contextTriggeredSaga = function*({
if (noticesToShow.length > 0) {
yield put(noticesFound(noticesToShow, tab));
} else {
// Will throw here when we will be able to not trigger context on dismissed/disliked notices
// throw new Error('Context was triggered but they were no notices left to display.');
yield put(noNoticesDisplayed(tab));
}
} catch (e) {
yield put(contextTriggerFailure(e, tab));
Expand Down

0 comments on commit cadc9c4

Please sign in to comment.