getListingsById: handle errors

This commit is contained in:
Vesa Luusua 2017-03-06 13:58:45 +02:00
parent 47e1b36df2
commit 309b7214be
2 changed files with 10 additions and 5 deletions

View file

@ -52,9 +52,8 @@ export class ListingPageComponent extends Component {
render() {
const { entitiesData, intl, params } = this.props;
const id = new types.UUID(params.id);
const currentListing = entitiesData.entities.listing
? getListingsById(entitiesData, [id])[0]
: null;
const listingsById = getListingsById(entitiesData, [id]);
const currentListing = listingsById.length > 0 ? listingsById[0] : null;
const title = currentListing ? currentListing.attributes.title : '';
const description = currentListing ? currentListing.attributes.description : '';

View file

@ -107,8 +107,14 @@ export default function sdkReducer(state = initialState, action = {}) {
* @param {Object} data the state part of the Redux store for this SDK reducer
* @param {Array<UUID>} listingIds listing IDs to select from the store
*/
export const getListingsById = (data, listingIds) =>
denormalisedEntities(data.entities, 'listing', listingIds);
export const getListingsById = (data, listingIds) => {
try {
return denormalisedEntities(data.entities, 'listing', listingIds);
} catch (e) {
console.error(`Could not denormalise entities with given ids (${listingIds.map(id => id.uuid)}). Error: ${e}`);
return [];
}
};
// ================ Action creators ================ //