* MM-11477 Use custom thunk middleware to intercept leaked network errors * MM-11477 Always include url in Client4 errors * Update redux
41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {
|
|
captureMessage,
|
|
cleanUrlForLogging,
|
|
LOGGER_JAVASCRIPT_WARNING,
|
|
} from 'app/utils/sentry';
|
|
|
|
// Creates middleware that mimics thunk while catching network errors thrown by Client4 that haven't
|
|
// been otherwise handled.
|
|
export function createThunkMiddleware() {
|
|
return (store) => (next) => (action) => {
|
|
if (typeof action === 'function') {
|
|
const result = action(store.dispatch, store.getState);
|
|
|
|
if (result instanceof Promise) {
|
|
return result.catch((error) => {
|
|
if (error.url) {
|
|
// This is a connection error from mattermost-redux. This should've been handled
|
|
// within the action itself, so we'll log to Sentry enough to identify where
|
|
// that handling is missing.
|
|
captureMessage(
|
|
`Caught Client4 error "${error.message}" from "${cleanUrlForLogging(error.url)}"`,
|
|
LOGGER_JAVASCRIPT_WARNING,
|
|
store
|
|
);
|
|
|
|
return {error};
|
|
}
|
|
|
|
throw error;
|
|
});
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
return next(action);
|
|
};
|
|
}
|