Skip to content

Commit

Permalink
fetchActions: Add Sentry logging for message-fetch errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbobbe authored and gnprice committed Jul 16, 2021
1 parent 06f07c0 commit ab62f73
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/message/__tests__/fetchActions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,12 @@ describe('fetchActions', () => {
});

describe('failure', () => {
beforeAll(() => {
// suppress `logging.warn` output
// $FlowFixMe[prop-missing]: Jest mock
logging.warn.mockReturnValue();
});

test('rejects when user is not logged in, dispatches MESSAGE_FETCH_ERROR', async () => {
const stateWithoutAccount = {
...baseState,
Expand Down
21 changes: 20 additions & 1 deletion src/message/fetchActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from '../actionConstants';
import { FIRST_UNREAD_ANCHOR, LAST_MESSAGE_ANCHOR } from '../anchor';
import { showErrorAlert } from '../utils/info';
import { ALL_PRIVATE_NARROW, apiNarrowOfNarrow } from '../utils/narrow';
import { ALL_PRIVATE_NARROW, apiNarrowOfNarrow, caseNarrow } from '../utils/narrow';
import { BackoffMachine, promiseTimeout, TimeoutError } from '../utils/async';
import { initNotifications } from '../notification/notificationActions';
import { addToOutbox, sendOutbox } from '../outbox/outboxActions';
Expand Down Expand Up @@ -133,6 +133,25 @@ export const fetchMessages = (fetchArgs: {|
error: e,
}),
);
logging.warn(e, {
message: 'Message-fetch error',

// Describe the narrow without sending sensitive data to Sentry.
narrow: caseNarrow(fetchArgs.narrow, {
stream: name => 'stream',
topic: (streamName, topic) => 'topic',
pm: ids => (ids.length > 1 ? 'pm (group)' : 'pm (1:1)'),
home: () => 'all',
starred: () => 'starred',
mentioned: () => 'mentioned',
allPrivate: () => 'all-pm',
search: query => 'search',
}),

anchor: fetchArgs.anchor,
numBefore: fetchArgs.numBefore,
numAfter: fetchArgs.numAfter,
});
throw e;
}
};
Expand Down

0 comments on commit ab62f73

Please sign in to comment.