Skip to content
This repository has been archived by the owner on Dec 30, 2021. It is now read-only.

Error: Invalid argument when use imgur.getCredits() #59

Closed
davidasync opened this issue Dec 29, 2018 · 3 comments
Closed

Error: Invalid argument when use imgur.getCredits() #59

davidasync opened this issue Dec 29, 2018 · 3 comments
Labels

Comments

@davidasync
Copy link

Hello I got error when trying to use getCredits api
Here's my piece of code

require('dotenv').load();

const Bluebird = require('bluebird');
const imgur = require('imgur');

imgur.setCredentials(
  process.env.IMGUR_EMAIL,
  process.env.IMGUR_PASSWORD,
  process.env.IMGUR_CLIENT_ID,
);

Bluebird.resolve()
  .then(async () => {
    const res = await imgur.getCredits();
    console.log(JSON.stringify(res, null, 2));
  })
  .catch(console.log)
  .finally(() => console.log('end'));

Seems like there's logic error at this code line 47 at imgur/lib/imgur.js

    if (!operation || typeof operation !== 'string' || ( !payload && operation !== ('credits' && 'search') ) ) {
        deferred.reject(new Error('Invalid argument'));
        return deferred.promise;
    }
@galbenyosef
Copy link

Hello I got error when trying to use getCredits api
Here's my piece of code

require('dotenv').load();

const Bluebird = require('bluebird');
const imgur = require('imgur');

imgur.setCredentials(
  process.env.IMGUR_EMAIL,
  process.env.IMGUR_PASSWORD,
  process.env.IMGUR_CLIENT_ID,
);

Bluebird.resolve()
  .then(async () => {
    const res = await imgur.getCredits();
    console.log(JSON.stringify(res, null, 2));
  })
  .catch(console.log)
  .finally(() => console.log('end'));

Seems like there's logic error at this code line 47 at imgur/lib/imgur.js

    if (!operation || typeof operation !== 'string' || ( !payload && operation !== ('credits' && 'search') ) ) {
        deferred.reject(new Error('Invalid argument'));
        return deferred.promise;
    }

Just encountered this also,
try replacing 'line 47' with this one:

if (!operation || typeof operation !== 'string' || ( !payload && ( (operation !== 'credits') && (operation !== 'search') ) ) )

operation !== ('credits' && 'search') is logically wrong.

@KenEucker
Copy link
Collaborator

@kaimallea the logic referenced in the comment above does seem incorrect:
https://github.com/kaimallea/node-imgur/blob/main/lib/imgur.js#L49

(!payload && operation !== ('credits' && 'search'))

Should change to something like this:

(!(operation && payload) || (['credits',search'].indexOf(operation) !== -1)) {

@kaimallea
Copy link
Owner

🎉 This issue has been resolved in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

4 participants