AxiosError Request failed with status code 502
Anonymous
TRIALOP

2 years 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

8 Replies

Anonymous
TRIALOP

2 years ago

async getQrCodeString (data: IPixQrCodeGenerateDTO, token: string): Promise {
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 = 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](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 = await axios.patch(
    url, jsonPayload,
    {
      httpsAgent: agent,
      headers: {
        Authorization: `Bearer ${token}`,
        Host: process.env.BB_HOST
      }
    }
  )
  console.log('qrcode is:', qrCodeExpiredPix)

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

}


2 years ago

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


Anonymous
TRIALOP

2 years 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


2 years ago

is this api thats failing running on railway?


Anonymous
TRIALOP

2 years ago

yes


2 years ago

have you checked its deploy logs?


Anonymous
TRIALOP

2 years ago

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


2 years ago

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


Loading...