diff --git a/functions/lib/bling-auth/create-auth.js b/functions/lib/bling-auth/create-auth.js index 4b95857..a6be9db 100644 --- a/functions/lib/bling-auth/create-auth.js +++ b/functions/lib/bling-auth/create-auth.js @@ -18,8 +18,7 @@ module.exports = (clientId, clientSecret, code, storeId, refreshToken) => new Pr axios.post(path, params.toString()) .then(({ data }) => resolve(data)) .catch(err => { - console.error(err.response?.data || err) - console.log('Deu erro', JSON.stringify(err)) + console.error('Deu erro s:', storeId, ' => ', JSON.stringify(err.response || err)) // console.log('Deu erro quero response status', err.response.status) if (!isRetry && err.response && err.response.status >= 429) { setTimeout(() => request(true), 7000) diff --git a/functions/lib/bling-auth/renovate-token.js b/functions/lib/bling-auth/renovate-token.js index fc179b3..72d0ba7 100644 --- a/functions/lib/bling-auth/renovate-token.js +++ b/functions/lib/bling-auth/renovate-token.js @@ -45,13 +45,15 @@ module.exports = async () => { ? maxDocs : (docs && docs.length) || 0 console.log('max existed docs', maxExistedDocs) + const promises = [] if (maxExistedDocs) { for (let i = 0; i < maxExistedDocs; i++) { const docRef = docs[i] if (docRef.data()?.storeId) { - handleAuth(docRef) + promises.push(handleAuth(docRef)) } } } + await Promise.all(promises) } }