juliuste / comboios

Comboios de Portugal (CP, Portugese Railways) API client.
ISC License
46 stars 9 forks source link

Random 302 Moved Temporarily errors #30

Open tiagorangel1 opened 9 months ago

tiagorangel1 commented 9 months ago

When trying to fetch too much journeys, it is possible to get the following error:

const error = new HTTPError(response, options);
              ^

GotError [HTTPError]: Response code 302 (Moved Temporarily)
    at EventEmitter.<anonymous> (<path>\node_modules\got\source\as-promise.js:74:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  host: 'api.cp.pt',
  hostname: 'api.cp.pt',
  method: 'POST',
  path: '/cp-api/oauth/token',
  socketPath: undefined,
  protocol: 'https:',
  url: 'https://api.cp.pt/cp-api/oauth/token',
  gotOptions: {
    path: '/cp-api/oauth/token',
    protocol: 'https:',
    slashes: true,
    auth: null,
    host: 'api.cp.pt',
    port: null,
    hostname: 'api.cp.pt',
    hash: null,
    search: null,
    query: null,
    pathname: '/cp-api/oauth/token',
    href: 'https://api.cp.pt/cp-api/oauth/token',
    retry: {
      retries: [Function (anonymous)],
      methods: Set(6) { 'GET', 'PUT', 'HEAD', 'DELETE', 'OPTIONS', 'TRACE' },
      statusCodes: Set(7) { 408, 413, 429, 500, 502, 503, 504 },
      errorCodes: Set(8) {
        'ETIMEDOUT',
        'ECONNRESET',
        'EADDRINUSE',
        'ECONNREFUSED',
        'EPIPE',
        'ENOTFOUND',
        'ENETUNREACH',
        'EAI_AGAIN'
      }
    },
    headers: {
      'user-agent': 'got/9.6.0 (https://github.com/sindresorhus/got)',
      accept: 'application/json',
      authorization: 'Basic <removed>',
      'content-type': 'application/x-www-form-urlencoded',
      'accept-encoding': 'gzip, deflate',
      'content-length': 29
    },
    hooks: {
      beforeRequest: [],
      beforeRedirect: [],
      beforeRetry: [],
      afterResponse: [],
      beforeError: [],
      init: []
    },
    decompress: true,
    throwHttpErrors: true,
    followRedirect: true,
    stream: false,
    form: false,
    json: false,
    cache: false,
    useElectronNet: false,
    body: 'grant_type=client_credentials',
    method: 'POST'
  },
  statusCode: 302,
  statusMessage: 'Moved Temporarily',
  headers: {
    server: 'nginx',
    date: 'Wed, 31 Jan 2024 08:54:31 GMT',
    'content-type': 'text/html',
    'content-length': '138',
    connection: 'close',
    location: 'https://www.cp.pt',
    'front-end-https': 'on',
    'strict-transport-security': 'max-age=31536000; includeSubdomains',
    'x-frame-options': 'DENY',
    'x-content-type-options': 'nosniff'
  },
  body: '<html>\r\n' +
    '<head><title>302 Found</title></head>\r\n' +
    '<body>\r\n' +
    '<center><h1>302 Found</h1></center>\r\n' +
    '<hr><center>nginx</center>\r\n' +
    '</body>\r\n' +
    '</html>\r\n'
}