Alteração para incluir o status 500 no erro a consulta a api da espacolazer

pull/20/head
adriano 2023-01-16 17:52:35 -03:00
parent ed42d76a6b
commit c952fa7960
3 changed files with 55 additions and 44 deletions

View File

@ -32,11 +32,15 @@ export const hit = async (req: Request, res: Response): Promise<Response> => {
if (req.headers["auth"] === '0424bd59b807674191e7d77572075f33') {
if (req.body['action'] === 'closed') {
}
else {
let contact = await ContactByCustomField(req.body['centro_custo'])
console.log('--------------> contact: ', contact)
if (contact) {
try {
@ -79,6 +83,8 @@ export const hit = async (req: Request, res: Response): Promise<Response> => {
}
}
}
else {
res.status(401).json({ "message": "Token Inválido!" });
}

View File

@ -41,7 +41,7 @@ const endPointQuery = async (url: string, method: string, param: string = '') =>
}
} catch (error) {
console.error(error);
console.error(`Erro ao consultar endpoint ${url}: ${error}`);
}
return response

View File

@ -306,8 +306,9 @@ async function sendDelayedMessages(wbot: Session, ticket: Ticket, contact: Conta
let endPointResponse = await endPointQuery(msgAction.actions[1], 'get')
console.log('Object.entries(endPointResponse.data).length: ', Object.entries(endPointResponse.data).length)
// console.log('endPointResonse.status: ',typeof(endPointResponse.status))
if (endPointResponse && Object.entries(endPointResponse.data).length > 0) {
if (endPointResponse && endPointResponse.status == 200 && Object.entries(endPointResponse.data).length > 0) {
// endPointResponse.data.categoria = 'ELOS'
// endPointResponse.data.categoria = 'INFRAESTRUTURA'
@ -450,10 +451,14 @@ async function sendDelayedMessages(wbot: Session, ticket: Ticket, contact: Conta
// }
}
else if (endPointResponse && Object.entries(endPointResponse.data).length == 0) {
else if (endPointResponse && endPointResponse.status == 200 && Object.entries(endPointResponse.data).length == 0) {
botSendMessage(ticket, contact, wbot, `Não existe nenhum chamado para consulta com esse número!\n _Digite *0* para voltar ao menu principal._`)
return
}
else if (endPointResponse && endPointResponse.status == 500) {
botSendMessage(ticket, contact, wbot, `Houve um erro ao realizar a consulta no sos espacolaser!\n _Digite *0* para voltar ao menu principal._`)
return
}
else {
botSendMessage(ticket, contact, wbot, `Desculpe, nao foi possível realizar a consulta!\n _Digite *0* para voltar ao menu principal._`)
return