AxiosError Request failed with status code 502

AnonymousTRIAL

a year ago

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

0 Replies

AnonymousTRIAL

a year ago

async getQrCodeString (data: IPixQrCodeGenerateDTO, token: string): Promise {
const txid = data.paymentInstallments.id.replace(/-/g, '')
const url = [https://${[process.env.BB](process.env.BB)_URL](https://${[process.env.BB](process.env.BB)_URL) ?? ''}/cob/${txid}?gw-dev-app-key=${[process.env.BB](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](process.env.BB)_PIX_RECEIVER,
  solicitacaoPagador: 'Name.'
}

const pfxPassword = [process.env.BB](process.env.BB)_CERTIFACTE_PASS
const pfx = Buffer.from([process.env.BB](process.env.BB)_CERTIFICATE ?? '', 'base64')

const agent = new https.Agent({
  pfx,
  passphrase: pfxPassword,
  rejectUnauthorized: true
})

const qrCode: AxiosResponse = await axios.put(
  url, jsonPayload,
  {
    httpsAgent: agent,
    headers: {
      Authorization: `Bearer ${token}`,
      Host: [process.env.BB](process.env.BB)_HOST
    }
  }
)

console.log('qrcode is:', qrcode)

const isExpired = await this.checkIfExpired([qrCode.data](qrCode.data).calendario.criacao, [qrCode.data](qrCode.data).calendario.expiracao)

if (isExpired) {
  const past = new Date([qrCode.data](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 = await axios.patch(
    url, jsonPayload,
    {
      httpsAgent: agent,
      headers: {
        Authorization: `Bearer ${token}`,
        Host: [process.env.BB](process.env.BB)_HOST
      }
    }
  )
  console.log('qrcode is:', qrCodeExpiredPix)

  return [qrCodeExpiredPix.data](qrCodeExpiredPix.data)
} else {
  return [qrCode.data](qrCode.data)
}

}


a year ago

502 would be returned from your services, please check the deploy logs for errors


AnonymousTRIAL

a year 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


a year ago

is this api thats failing running on railway?


AnonymousTRIAL

a year ago

yes


a year ago

have you checked its deploy logs?


AnonymousTRIAL

a year ago

omg, I founded the problem, was the call for other services that is offline, I'm sorry


a year ago

no worries, for the future, please dont be so quick to look at railway with the blame.