Skip to content

Commit

Permalink
fix: associate provider name with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Dec 28, 2023
1 parent a947c1f commit 4ead124
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/avatar/auto.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ const getAvatarContent = name => async input => {
return { type: 'url', data: url }
}

const getAvatar = async (fn, ...args) => {
const promise = Promise.resolve(fn(...args))
.then(getAvatarContent(fn.name))
const getAvatar = async (fn, { name, args }) => {
const promise = fn(args)
.then(getAvatarContent(name))
.catch(error => {
isIterable.forEach(error, error => {
error.statusCode = error.statusCode ?? error.response?.statusCode
error.name = fn.name
error.name = name
})
throw error
})

return pTimeout(promise, AVATAR_TIMEOUT).catch(error => {
error.name = fn.name
error.name = name
throw error
})
}

module.exports = async args => {
const collection = providersBy[is(args)]
const promises = collection.map(providerName =>
pTimeout(getAvatar(providers[providerName], args), AVATAR_TIMEOUT)
const promises = collection.map(name =>
pTimeout(getAvatar(providers[name], { name, args }), AVATAR_TIMEOUT)
)
return pAny(promises)
}
Expand Down

0 comments on commit 4ead124

Please sign in to comment.