Add log.duck.js

Logging requests from duck files can now be dispatched to a logging
thunk action that does not interrupt the application.
This commit is contained in:
Hannu Lyytikainen 2017-09-29 15:16:50 +03:00
parent e35628660c
commit 3c4f20f2ad
4 changed files with 22 additions and 9 deletions

View file

@ -1,7 +1,7 @@
import { pick } from 'lodash';
import { updatedEntities, denormalisedEntities } from '../../util/data';
import * as propTypes from '../../util/propTypes';
import * as log from '../../util/log';
import { logError } from '../../ducks/log.duck';
import { fetchCurrentUserHasOrdersSuccess } from '../../ducks/user.duck';
// ================ Action types ================ //
@ -120,7 +120,7 @@ export const initiateOrder = params =>
})
.catch(e => {
dispatch(initiateOrderError(e));
log.error(e);
dispatch(logError(e));
throw e;
});
};
@ -163,7 +163,7 @@ export const speculateTransaction = (listingId, bookingStart, bookingEnd) =>
dispatch(speculateTransactionSuccess(tx));
})
.catch(e => {
log.error(e);
dispatch(logError(e));
return dispatch(speculateTransactionError(e));
});
};

View file

@ -1,7 +1,7 @@
import { omit, omitBy, isUndefined } from 'lodash';
import { types } from '../../util/sdkLoader';
import * as log from '../../util/log';
import { addMarketplaceEntities } from '../../ducks/marketplaceData.duck';
import { logError } from '../../ducks/log.duck';
import { fetchCurrentUserHasListingsSuccess } from '../../ducks/user.duck';
const requestAction = actionType => params => ({ type: actionType, payload: { params } });
@ -280,7 +280,7 @@ export function requestCreateListing(data) {
return response;
})
.catch(e => {
log.error(e, { listingData: cleanedData });
dispatch(logError(e, { listingData: cleanedData }));
return dispatch(createListingError(e));
});
};
@ -319,7 +319,7 @@ export function requestUpdateListing(tab, data) {
dispatch(updateListingSuccess(updateResponse));
})
.catch(e => {
log.error(e, { listingData: cleanedData });
dispatch(logError(e, { listingData: cleanedData }));
return dispatch(updateListingError(e));
});
};

View file

@ -1,8 +1,8 @@
import { types } from '../../util/sdkLoader';
import * as propTypes from '../../util/propTypes';
import * as log from '../../util/log';
import { addMarketplaceEntities } from '../../ducks/marketplaceData.duck';
import { fetchCurrentUserNotifications } from '../../ducks/user.duck';
import { logError } from '../../ducks/log.duck';
// ================ Action types ================ //
@ -144,7 +144,7 @@ export const acceptSale = id =>
return response;
})
.catch(e => {
log.error(e, { txId: id, transition: propTypes.TX_TRANSITION_ACCEPT });
dispatch(logError(e, { txId: id, transition: propTypes.TX_TRANSITION_ACCEPT }));
dispatch(acceptSaleError(e));
throw e;
});
@ -166,7 +166,7 @@ export const rejectSale = id =>
return response;
})
.catch(e => {
log.error(e, { txId: id, transition: propTypes.TX_TRANSITION_REJECT });
dispatch(logError(e, { txId: id, transition: propTypes.TX_TRANSITION_REJECT }));
dispatch(rejectSaleError(e));
throw e;
});

13
src/ducks/log.duck.js Normal file
View file

@ -0,0 +1,13 @@
/**
* A utility duck file that can be used to log errors
* asynchronously without interrupting other thunks.
*/
import * as log from '../util/log';
// ================ Thunks ================ //
export const logError = (error, data) =>
(dispatch, getState, sdk) => {
log.error(error, data);
};