I try to fetch results from an API and store these into a front-side database with a function that return a Promise. I'm doing it in a Redux Epic with the following code:
export default (action$) =>
action$.pipe(
ofType(PATIENT_MINUTE_BLOCKS_FETCH),
switchMap(({payload}) => {
const {id, dateStart, dateEnd} = payload
// this is the API call
return fetchSessionMinuteBlocks({
patientId: id,
dateStart: moment(dateStart).format('YYYY-MM-DD'),
dateEnd: moment(dateEnd).format('YYYY-MM-DD')
}).pipe(
mergeMap(response => {
if (!('errors' in response)) {
let {data: {sessionMetricsMinuteBlocks}} = response
// this is where I return either failure or success after storeSessionMinuteBlocks resolution
return from(storeSessionMinuteBlocks(id, sessionMetricsMinuteBlocks))
.pipe(of(patientMinuteBlocksFetchFulfilled()))
}
return of(patientMinuteBlocksFetchFailure(response))
}),
catchError(error => {
console.error('ERROR : ', error)
return of(patientMinuteBlocksFetchFailure(error.graphQLErrors))
})
)
})
)
Here is the content of the storeSessionMinuteBlocks function:
export default (id, data) => {
if (data && data.list) {
return new Promise(resolve => {
db.then(db => {
/** Bulk insert into RxDB */
db.session_minute_blocks.pouch.bulkDocs(
data.list.map(value => {
/* Remove __typename from object as it's a forbidden property in pouchDB schema */
const {
__typename,
...elem
} = value
return {
...elem,
sessionId: `${value.sessionId}`,
patientId: id
}
})
)
.then(result => resolve(result))
.catch(error => console.error(error))
})
})
}
}
The catchError is triggered, and I get the following error when the API call is done:

If I log the results returned by when the bulkDocs function has finished, every rows are nicely inserted in database. Like this:
and so on ...
I tried to:
- Get rid of the
new Promise - directly returns Promise made bulkDocs
- return (or not) the resolve value
- Verify my imports
- re-install deps and rebuild the project
I even have a very similar piece of code that works.
I don't understand why this error ? I could find only one reference to it on the internet, and it has nothing to do with my context. Is there a super hero here, who have a bloody idea what can cause this ? thanks !