export class WhatsappWebClient implements SendWhatsappWeb {
private readonly api: AxiosInstance
constructor (private config: WhatsappWebConfig = generalConfigs.clients.whatsapp.whatsappWeb) {
this.api = axios.create({
baseURL: this.config.url
})
}
async send ({ phoneNumber, message }: SendWhatsappWeb.Input): Promise<void> {
try {
await this.api.post('/message', {
phoneNumber,
message
})
logger.info('Successfully sent whatsapp message.')
} catch (error) {
if (!axios.isAxiosError(error)) {
// If it's not an AxiosError, we throw a generic error
throw new Error('An error occurred while sending the whatsapp message.')
}
const axiosError = error as AxiosError
if (axiosError.response) {
// If there's a response, it means the request was made and the server responded with a status code outside the range of 2xx
const errorMessage = `Error when calling WhatsApp Web: ${axiosError.response.status} - ${axiosError.response.statusText}`
logger.error(errorMessage)
throw new Error(errorMessage)
} else if (axiosError.request) {
// If there's a request, it means the request was made but no response was received
logger.error('No response received from WhatsApp Web.')
throw new Error('No response received from WhatsApp Web.')
} else {
// Otherwise, it's just a generic error
logger.error('An error occurred while sending the whatsapp message.')
throw new Error('An error occurred while sending the whatsapp message.')
}
}
}
Error: Evaluation failed: Error: wid error: invalid wid
at e (https://web.whatsapp.com/:2:4910)
at new f (https://web.whatsapp.com/app.febe97f47327a63e0d22.js:306:201531)
at Object.c [as createWid] (https://web.whatsapp.com/app.febe97f47327a63e0d22.js:306:207832)
at __puppeteer_evaluation_script__:2:53
Steps to Reproduce the Bug or Issue
run the API
send a request in postman passing a string with leathers instead numbers
Is there an existing issue for this?
Describe the bug
at e (https://web.whatsapp.com/:2:4910) at new f (https://web.whatsapp.com/app.febe97f47327a63e0d22.js:306:201531) at Object.c [as createWid] (https://web.whatsapp.com/app.febe97f47327a63e0d22.js:306:207832) at puppeteer_evaluation_script:2:53
I forced an error in the phone property passing a string with letters instead numbers. I'm trying to catch the error in the API like this:
and in a client in my own API:
but doesn't work.
Expected behavior
As a user, I expect that errors been catch in
and not in:
Steps to Reproduce the Bug or Issue
Relevant Code
Browser Type
Chromium
WhatsApp Account Type
Standard
Does your WhatsApp account have multidevice enabled?
No, I am not using Multi Device
Environment
Linux Ubuntu
Additional context
No response