mattermost-mobile/app/store/middlewares/thunk.js
Daniel Espino García 4c8594d330
Add linter rules for import order and type member delimiters (#5514)
* Add linter rules for import order and type member delimiters

* Remove unneeded group

* Group all app/* imports before the internal imports

* Move app/ imports before parent imports

* Separate @node_modules imports into a different group

* Substitute app paths by aliases

* Fix @node_modules import order and add test related modules

* Add aliases for types and test, and group import types
2021-07-23 11:06:04 +02:00

39 lines
1.3 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {
captureMessage,
cleanUrlForLogging,
LOGGER_JAVASCRIPT_WARNING,
} from '@utils/sentry';
// Creates middleware that mimics thunk while catching network errors thrown by Client4 that haven't
// been otherwise handled.
export default (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 app/mm-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);
};