mirror of
https://github.com/kingomarnajjar/flex-template-web.git
synced 2026-07-26 06:47:17 +10:00
getListingsById: handle errors
This commit is contained in:
parent
47e1b36df2
commit
309b7214be
2 changed files with 10 additions and 5 deletions
|
|
@ -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 : '';
|
||||
|
|
|
|||
|
|
@ -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 ================ //
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue