Closed Dayjo closed 7 years ago
@Dayjo Yes they get through to the catch
block on the api call but it's because in api.js
it rejects the promise if the object is an Error object. You could move the parsing into a separate function so we could test for it...
destroys more of the coverage
I assume it's fine to add a property to an Error
. I doesn't seem to have any negative effects as far as I can see.
Any suggestion how I should test this? The way I was testing this was to edit the endpoint but as it's not a parameter not sure how to go about doing a test for it. Can probably test this once the Multiple Keywords is merged in as if you supply more than 5 terms, google 404s (though perhaps it should internally catch that error rather than doing the request and failing).
The best way to test it would probably be to move it to a separate function and then intentionally send it malformed JSON. Then you can check that the error response is as expected.
Hopefully I will be able to get your PR's merged in today.
I've updated this with tests.
Let me know if it could be done better! :)
Aw god damnit even more coverage fail haha. Anyways, it's home time!
@Dayjo Looks good! Have some merge conflicts to resolve now, but when that's done I can approve the PR. Once this PR is merged in I'll release a new npm version.
Ugh, git is being a git about the conflicts.
@Dayjo Hmm, I'm going to .gitignore
the build files - that will stop all these merge conflicts.
@pat310 yeah good idea! Why the hell it's decided to conflict that addition in utilities.js I have no idea.
@Dayjo Delete your lib
folder, pull master and merge it into your branch. Then try to resolve any remaining merge conflicts (shouldn't be much). Let me know if you have problems.
Ok so I've totally gone and screwed this one up haha. I clearly have an awful workflow for dealing with forks.
@Dayjo I resolved the merge conflict, can you just correct these last few codeclimate issues?
Phew!
@Dayjo Good job!!
@Dayjo Just published version 4.1.0 with the multiple keywords and JSON parse catch. Thanks!
Whoop! 🎉
Nice one, thanks for the assistance. Feels good to finally be able to contribute to some open source stuff while still at work!
This simply wraps the JSON parsing of the request in a try catch so we can throw an error.
It might be useful for us to throw an object containing the error and the body of the request so that the problem can be identified.
The other option would be to follow what you've done in constructObj and use
new Error
and return that, that way we can write a test for it. Do those get through to the.catch((err) ...
on the api call?@pat310 Any preference on the throwing vs returning
new Error
?