Skip to content

Commit

Permalink
refactor: fail late when bulk creating entities
Browse files Browse the repository at this point in the history
  • Loading branch information
m90 committed Aug 6, 2024
1 parent 9a6ce98 commit 9da79ce
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@ export default class WikibaseRepository {
if (!this.edit) {
return Promise.reject(new Error('Cannot edit a read only instance.'))
}
return Promise.all(entities.map(async entity => {
return Promise.allSettled(entities.map(async entity => {
return this.edit.entity.create(entity)
}))
.then((results) => {
for (const result of results) {
if (result.status === 'rejected') {
throw new Error(result.reason)
}
}
return results.map(v => v.value)
})
}

getEntities (...identifiers) {
Expand Down

0 comments on commit 9da79ce

Please sign in to comment.