@talend/react-cmf
Version:
A framework built on top of best react libraries
34 lines (32 loc) • 1.11 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.URL_REQUIRED_MESSAGE = void 0;
exports.default = getErrorMiddleware;
var _invariant = _interopRequireDefault(require("invariant"));
var _http = _interopRequireDefault(require("../../actions/http"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const URL_REQUIRED_MESSAGE = exports.URL_REQUIRED_MESSAGE = 'url to post the error is required';
/**
* create a middleware which post request to server
* @param {String} url or path of the api like /api/errors
* @return {function} middleware
*/
function getErrorMiddleware(url) {
(0, _invariant.default)(url, URL_REQUIRED_MESSAGE);
return store => next => action => {
try {
return next(action);
} catch (error) {
return next(_http.default.post(url, {
userAgent: navigator ? navigator.userAgent : 'unknown',
reduxState: store.state,
action,
error
}));
}
};
}
getErrorMiddleware.URL_REQUIRED_MESSAGE = URL_REQUIRED_MESSAGE;
//# sourceMappingURL=index.js.map
;