Skip to content

Commit

Permalink
fix: handling 404 errors on customer list from freteclick api
Browse files Browse the repository at this point in the history
  • Loading branch information
leomp12 committed Sep 16, 2024
1 parent a1027d7 commit c993ae1
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions functions/lib/freteclick/customer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,30 @@ const freteClickApi = require('./client')
const ecomUtils = require('@ecomplus/utils')

module.exports = async (token, customer, address) => {
const { data } = await freteClickApi({
url: `/people/customer?email=${customer.main_email}`,
method: 'get',
token
}, {
validateStatus (status) {
return status === 200
try {
const { data } = await freteClickApi({
url: `/people/customer?email=${customer.main_email}`,
method: 'get',
token
}, {
validateStatus (status) {
return status === 200
}
})
if (!data?.response?.data) {
const err = new Error('Unexpected Freteclick response on customer list')
err.data = data
throw err
}
})
if (!data?.response?.data) {
const err = new Error('Unexpected Freteclick response on customer list')
err.data = data
throw err
}
const { id: listedCustomerId } = data.response.data
if (listedCustomerId) {
return {
id: listedCustomerId
const { id: listedCustomerId } = data.response.data
if (listedCustomerId) {
return {
id: listedCustomerId
}
}
} catch (error) {
if (error.response?.status !== 404) {
throw error
}
}
const body = {
Expand Down

0 comments on commit c993ae1

Please sign in to comment.