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

Search not working with Promise #27

Closed
lauritzsh opened this issue Nov 2, 2016 · 2 comments
Closed

Search not working with Promise #27

lauritzsh opened this issue Nov 2, 2016 · 2 comments
Labels

Comments

@lauritzsh
Copy link

lauritzsh commented Nov 2, 2016

Hey, great library. Nice with automatic rate limiting.

Database searching with Promise is not working for me however. For example

db.search('skrillex', { type: 'label' }, (err, res) => {
  console.log(res);
})

is returning just five items like their own API with https://api.discogs.com/database/search?q=skrillex&type=label&token=[redacted]. However if I am using a Promise like

db.search('skrillex', { type: 'label' })
  .then(console.log)

I get 870 items with all sorts of different results. Basically everything with Skrillex I assume.

Should it instead of this

if(arguments.length <= 2){
	if(typeof params === 'function'){ callback = params; } // No extra search params, the callback is the second function param
}else{
	obj = params;
}

just be a simple && check

if(arguments.length <= 2 && typeof params === 'function'){
	callback = params; // No extra search params, the callback is the second function param
}else{
	obj = params;
}

since the length is <= 2 but params is not a function, obj should just be set to params. I will create a pull request for you, just checking first that the logic is sound.

@bartve
Copy link
Owner

bartve commented Nov 3, 2016

It's slightly more subtle. This way obj will end up being undefined when you just add 1 param. Will add a fix today. Thanks for reporting!

@bartve bartve closed this as completed Nov 3, 2016
@bartve bartve added the bug label Nov 3, 2016
@lauritzsh
Copy link
Author

That's true, good catch. I see you have fixed it, very nice! Thank you.

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

No branches or pull requests

2 participants