Mondanzo/node-curseforge

Exception when page size too large

jojo2357 opened this issue · 15 comments

i ran each command

cf.search_mods(mc, {searchFilter: "void totem (forge)", index: 0, pageSize: 100})
cf.search_mods(mc, {searchFilter: "j", index: 0, pageSize: 100})
cf.search_mods(mc, {searchFilter: "j", index: 1, pageSize: 100})

and got this error every time i ran it.

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (.\node_modules\node-curseforge\dist\utils.js:50:34)
    at IncomingMessage.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1223:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

I am currently looking at how to solve #1 and I will also look into this. I suspect it is a simple fix here

Update: actually happens when the response code is not correct, and thus the response is empty. I thought it was for too large a page but in fact that does not directly cause the error

More information, i am actually getting a 400 error, which is "Bad Request" so this probably wasnt the fix

For which ones are you getting 400 bad request?

search_mods, this is the request

ClientRequest {
  _events: [Object: null prototype] {
    socket: [Function: bound onceWrapper] { listener: [Function: onSocket] }
  },
  _eventsCount: 1,
  _maxListeners: undefined,
  outputData: [],
  outputSize: 0,
  writable: true,
  _last: true,
  chunkedEncoding: false,
  shouldKeepAlive: false,
  useChunkedEncodingByDefault: false,
  sendDate: false,
  _removedConnection: false,
  _removedContLen: false,
  _removedTE: false,
  _contentLength: null,
  _hasBody: true,
  _trailer: '',
  finished: false,
  _headerSent: false,
  socket: null,
  connection: null,
  _header: null,
  _keepAliveTimeout: 0,
  _onPendingData: [Function: noopPendingOutput],
  agent: Agent {
    _events: [Object: null prototype] {
      free: [Function],
      newListener: [Function: maybeEnableKeylog]
    },
    _eventsCount: 2,
    _maxListeners: undefined,
    defaultPort: 443,
    protocol: 'https:',
    options: { path: null },
    requests: {},
    sockets: { 'api.curseforge.com:443::::::::::::::::::': [Array] },
    freeSockets: {},
    keepAliveMsecs: 1000,
    keepAlive: false,
    maxSockets: Infinity,
    maxFreeSockets: 256,
    maxTotalSockets: Infinity,
    totalSocketCount: 1,
    maxCachedSessions: 100,
    _sessionCache: { map: {}, list: [] },
    [Symbol(kCapture)]: false
  },
  socketPath: undefined,
  method: 'GET',
  insecureHTTPParser: undefined,
  path: '/v1/mods/search?gameId=432&searchFilter=void+totem&index=1&pageSize=100',
  _ended: false,
  res: null,
  aborted: false,
  timeoutCb: null,
  upgradeOrConnect: false,
  parser: null,
  maxHeadersCount: null,
  reusedSocket: false,
  host: 'api.curseforge.com',
  protocol: 'https:',
  [Symbol(kCapture)]: false,
  [Symbol(kNeedDrain)]: false,
  [Symbol(corked)]: 0,
  [Symbol(kOutHeaders)]: [Object: null prototype] {
    accept: [ 'Accept', 'application/json' ],
    'x-api-key': [
      'x-api-key',
      '<redacted>'
    ],
    host: [ 'Host', 'api.curseforge.com' ]
  }
}

Using command-line curl, I am finding that there is some strange behavior once it finishes the request, something about Could not resolve host: application. This just might be a curseforge problem but I wouldnt rule other things out yet.

They advertise this for shell, but i used bash anyway:
curl -X GET /v1/mods/search?gameId=0 -H 'Accept: application/json' -H 'x-api-key: API_KEY'

I tried querying with less items and it seems like CF has a set limit which isn't documented

After further trying out it seems like 50 is the limit for querying

Can confirm this from command line to be true, but I also still get the same curl: (6) Could not resolve host: application and it does not immediately deny the request

Could you send the whole command you used?

curl -X GET "https://api.curseforge.com/v1/mods/search?gameId=432" -H 'Accept: application/json' -H "x-api-key: <redacted>"

maybe the mix of using ' and " screws up the command?

I checked on windows, changing that removes the application message, doesnt fix page size 100 and on unix there is just no output at all

I spoke with CF, there is a limit of 50, and they are going to add it to the documentation promptly. I will also add the check to the lib.

If you add it to the lib it would prolly be best to just automatically query multiple requests until the requested limit is reached or the items are all queried

Yeah thats easy enough, i am a little busy today, so I will try to get a pr for 1 and 2 to you then. Also I dont specialize in typescript, so right now the best that I can do is

const cf = require('node-curseforge').Curseforge;

Or, `const { Curseforge, Game } = require('node-curseforge');

Which I still think is better than using default as a constructor, as it gets fairly close to the intended behavior.