Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If API3_MAX_LIMIT set in Heroku config vars, cause V3 api to error #8297

Open
hamishnorton opened this issue Sep 27, 2024 · 0 comments
Open

Comments

@hamishnorton
Copy link

Describe the bug
If you set "API3_MAX_LIMIT": "1000", such as in Heroku config vars, your V3 API errors on every call.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'lib/api3/const.json', set: "API3_MAX_LIMIT": "1000"
  2. Call https://<app-name>.herokuapp.com/api/v2/authorization/request/<api-token>
  3. Call https://<app-name>.herokuapp.com/api/v3/entries with a valid Bearer token
  4. See error in the response: {"status": 500, "message": "Database error"}

Expected behavior
The api call should not error, but instead return data that matches the query.

Your setup information

  • NightScout version: "version": "15.0.2"
  • Dexcom G7 from AAPS
  • Issue is sepecific to Heroku hosting, but it may also affect other hosting if the config vars are set as strings, and not numbers (when it's a number).

Additional context
Modifying `/lib/api3/generic/collection.js ln:70 onwards with...

  self.parseLimit = function parseLimit (req, res) {
    const maxLimit = parseInt(app.get('API3_MAX_LIMIT'), 1000);
    let limit = maxLimit;

    if (req.query.limit) {
      if (!isNaN(req.query.limit) && req.query.limit > 0 && req.query.limit <= maxLimit) {
        limit = parseInt(req.query.limit, 1000);
      }
      else {
        opTools.sendJSONStatus(res, apiConst.HTTP.BAD_REQUEST, apiConst.MSG.HTTP_400_BAD_LIMIT);
        return null;
      }
    }

    return limit;
  };

might work, but I'm not a node/JS guy.
It appears that the code can't cope if the value is a string instead of a number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant