R
Railway8mo ago
Kimitri

AxiosError Request failed with status code 502

I have an API host on Railway that have an endpoint that worked well with generates qrcode, but suddenly all requests to this endpoint is return this error 502 with this message AxiosError Request failed with status code 502. Railway change something in the last weeks that changed the environments? The endpoint makes an request to other api, and in this request I send a http.Agent, take a look bellow
Solution:
omg, I founded the problem, was the call for other services that is offline, I'm sorry
Jump to solution
9 Replies
Percy
Percy8mo ago
Project ID: N/A
Kimitri
KimitriOP8mo ago
async getQrCodeString (data: IPixQrCodeGenerateDTO, token: string): Promise<IBBPixResponseDTO> { const txid = data.paymentInstallments.id.replace(/-/g, '') const url = https://${process.env.BB_URL ?? ''}/cob/${txid}?gw-dev-app-key=${process.env.BB_APP_KEY ?? ''} const jsonPayload = { calendario: { expiracao: 36000 }, devedor: { cpf: data.cpf ?? '', nome: data.customer }, valor: { original: ${data.amount} }, chave: process.env.BB_PIX_RECEIVER, solicitacaoPagador: 'Name.' } const pfxPassword = process.env.BB_CERTIFACTE_PASS const pfx = Buffer.from(process.env.BB_CERTIFICATE ?? '', 'base64') const agent = new https.Agent({ pfx, passphrase: pfxPassword, rejectUnauthorized: true }) const qrCode: AxiosResponse<IBBPixResponseDTO> = await axios.put( url, jsonPayload, { httpsAgent: agent, headers: { Authorization: Bearer ${token}, Host: process.env.BB_HOST } } ) console.log('qrcode is:', qrcode) const isExpired = await this.checkIfExpired(qrCode.data.calendario.criacao, qrCode.data.calendario.expiracao) if (isExpired) { const past = new Date(qrCode.data.calendario.criacao) const now = new Date() const differenceInMilliseconds = now.getTime() - past.getTime() const differenceInSeconds = Math.floor(differenceInMilliseconds / 1000) jsonPayload.calendario.expiracao = differenceInSeconds + 36000 const qrCodeExpiredPix: AxiosResponse<IBBPixResponseDTO> = await axios.patch( url, jsonPayload, { httpsAgent: agent, headers: { Authorization: Bearer ${token}, Host: process.env.BB_HOST } } ) console.log('qrcode is:', qrCodeExpiredPix) return qrCodeExpiredPix.data } else { return qrCode.data } }
Brody
Brody8mo ago
502 would be returned from your services, please check the deploy logs for errors
Kimitri
KimitriOP8mo ago
the console.log shows me data retrieved 200, but the my api falls with 502 from axios, but this code was working the past weeks and I didn't change nothing and it stopped to work
Brody
Brody8mo ago
is this api thats failing running on railway?
Kimitri
KimitriOP8mo ago
yes
Brody
Brody8mo ago
have you checked its deploy logs?
Solution
Kimitri
Kimitri8mo ago
omg, I founded the problem, was the call for other services that is offline, I'm sorry
Brody
Brody8mo ago
no worries, for the future, please dont be so quick to look at railway with the blame.
Want results from more Discord servers?
Add your server