Skip to content

Commit

Permalink
LogError only pushes to db and posts to Slack if not dev
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunsaker committed Jul 1, 2018
1 parent 8a3aa3c commit 892276c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
15 changes: 1 addition & 14 deletions sagas/errors/logError/__tests__/logError.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ describe('logError saga', () => {
it('should have yielded all of our actions', (result) => {
expect(result).toEqual(
all([
put({
type: 'pushData',
payload: {
data,
ref: 'errors',
},
}),
// NOTE: Since, __DEV__, pushData should not be called
put({
type: 'SET_SYSTEM_MESSAGE',
payload: {
Expand All @@ -56,13 +50,6 @@ describe('logError saga', () => {
it('should have yielded all of our actions', (result) => {
expect(result).toEqual(
all([
put({
type: 'pushData',
payload: {
data,
ref: 'errors',
},
}),
put({
type: 'SET_SYSTEM_MESSAGE',
payload: {
Expand Down
34 changes: 22 additions & 12 deletions sagas/errors/logError/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import config from '../../../config';
export default function* logError(action) {
/*
This should
- Log the error to the db
- SET_SYSTEM_MESSAGE
- Post it to Slack if Slack config has been set up
- If in production:
- Log the error to the db
- SET_SYSTEM_MESSAGE
- If Slack config has been set up
- Post to Slack
- If in development
- SET_SYSTEM_MESSAGE
*/

try {
Expand All @@ -20,13 +24,6 @@ export default function* logError(action) {
};

const actions = [
put({
type: 'pushData',
payload: {
data,
ref: 'errors',
},
}),
put({
type: 'SET_SYSTEM_MESSAGE',
payload: {
Expand All @@ -35,6 +32,15 @@ export default function* logError(action) {
error: true,
}),
];

const databaseAction = put({
type: 'pushData',
payload: {
data,
ref: 'errors',
},
});

const slackAction = put({
type: 'post',
payload: {
Expand All @@ -49,8 +55,12 @@ export default function* logError(action) {
},
});

if (config.slack.webhook) {
actions.push(slackAction);
if (!__DEV__) {
actions.push(databaseAction);

if (config.slack.webhook) {
actions.push(slackAction);
}
}

yield all(actions);
Expand Down

0 comments on commit 892276c

Please sign in to comment.