diff --git a/package.json b/package.json index 5f7d714..0014995 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@poap-xyz/poap-family", - "version": "1.8.6", + "version": "1.8.7", "author": { "name": "POAP", "url": "https://poap.xyz" diff --git a/src/loaders/api.js b/src/loaders/api.js index 76c0382..141fdc6 100644 --- a/src/loaders/api.js +++ b/src/loaders/api.js @@ -14,6 +14,12 @@ async function putEventAndOwners(event, owners) { }, body: JSON.stringify({ event, owners }), }) + if (response.status === 400) { + throw new Error(`Event ${event.id} save failed: incorrect data given`) + } + if (response.status === 503) { + throw new Error(`Event ${event.id} save failed: server cannot fetch data`) + } if (response.status !== 200 && response.status !== 201) { throw new Error(`Event ${event.id} save failed (status ${response.status})`) } @@ -104,6 +110,12 @@ async function patchEvents(events) { }, body: JSON.stringify(events), }) + if (response.status === 400) { + throw new Error(`Events save failed: incorrect data given`) + } + if (response.status === 503) { + throw new Error(`Events save failed: server cannot fetch data`) + } if (response.status !== 200 && response.status !== 201) { throw new Error(`Events save failed (status ${response.status})`) } @@ -331,6 +343,12 @@ async function putEventOwners(eventId, owners) { }, body: JSON.stringify(owners), }) + if (response.status === 400) { + throw new Error(`Event ${eventId} save owners failed: incorrect data given`) + } + if (response.status === 503) { + throw new Error(`Event ${eventId} save owners failed: server cannot fetch data`) + } if (response.status !== 200 && response.status !== 201) { throw new Error(`Event ${eventId} save owners failed (status ${response.status})`) } diff --git a/src/loaders/event.js b/src/loaders/event.js index b798885..ddbcd08 100644 --- a/src/loaders/event.js +++ b/src/loaders/event.js @@ -183,7 +183,9 @@ async function eventLoader({ params, request }) { const owners = tokens.map((token) => token.owner.id) const uniqueOwners = owners.filter((value, index, all) => all.indexOf(value) === index) const filteredOwners = uniqueOwners.filter((owner) => !IGNORED_OWNERS.includes(owner)) - putEventAndOwners(event, filteredOwners) + putEventAndOwners(event, filteredOwners).catch((err) => { + console.error(err) + }) return { event, owners: filteredOwners, @@ -305,7 +307,9 @@ async function eventsLoader({ params, request }) { }) } } - patchEvents(Object.values(events)) + patchEvents(Object.values(events)).catch((err) => { + console.error(err) + }) return events } diff --git a/src/pages/Event.js b/src/pages/Event.js index f7b20f5..dffd4fe 100644 --- a/src/pages/Event.js +++ b/src/pages/Event.js @@ -121,12 +121,10 @@ function Event() { ) setCaching(true) setCachingError(null) - Promise - .all([ - patchEvents(Object.values(eventsProcessed)), - putEventInCommon(event.id, inCommonProcessed), - ]) - .then( + patchEvents(Object.values(eventsProcessed)).catch((err) => { + console.error(err) + }) + putEventInCommon(event.id, inCommonProcessed).then( () => { setCaching(false) setCachedTs(Math.trunc(Date.now() / 1000)) diff --git a/src/pages/Events.js b/src/pages/Events.js index 4d70824..64803fc 100644 --- a/src/pages/Events.js +++ b/src/pages/Events.js @@ -128,7 +128,9 @@ function Events() { const newOwners = [...new Set(eventOwnerTokens.map((token) => token.owner.id))] const newOwnersFilters = newOwners.filter((owner) => !IGNORED_OWNERS.includes(owner)) setOwners((prevOwners) => ({ ...prevOwners, [eventId]: newOwnersFilters })) - putEventOwners(eventId, newOwnersFilters) + putEventOwners(eventId, newOwnersFilters).catch((err) => { + console.error(err) + }) return Promise.resolve() } return Promise.reject(new Error(`Tokens for drop '${eventId}' missing`)) @@ -164,7 +166,9 @@ function Events() { if (Array.isArray(eventOwnerTokens)) { const newOwners = [...new Set(eventOwnerTokens.map((token) => token.owner.id))] setOwners((prevOwners) => ({ ...prevOwners, [eventId]: newOwners })) - putEventOwners(eventId, newOwners) + putEventOwners(eventId, newOwners).catch((err) => { + console.error(err) + }) } else { return Promise.reject(new Error(`Tokens for drop '${eventId}' missing`)) } @@ -528,12 +532,10 @@ function Events() { ) removeErrors(eventId) setLoading((alsoLoading) => ({ ...alsoLoading, [eventId]: LOADING_CACHING })) - Promise - .all([ - patchEvents(Object.values(eventsProcessed)), - putEventInCommon(eventId, inCommonProcessed), - ]) - .then( + patchEvents(Object.values(eventsProcessed)).catch((err) => { + console.error(err) + }) + putEventInCommon(eventId, inCommonProcessed).then( () => { setEventData((prevEventData) => ({ ...prevEventData,