Conversation
|
@callmehiphop honest talk time. The code in Vision.prototype.detect is kind of out of control. Considering this latest refactoring: https://gist.github.com/stephenplusplus/aa0c82b4939e5901680e41c9a89e8c03 -- can you think of a way I can trim down the insanity? |
|
What are your feelings on moving things outside of the function? We have several maps and inner functions used to massage data that could easily live as a static/private members. |
|
I made an attempt at moving them outside as static members. The issue I ran into was losing access to variables that held the original response, the types the user originally requested, and the shorthand->formalApiName lookup tables. I'll just leave things like they are in the gist for now, and move on with this PR. If I can't come up with a good refactoring plan before we merge, I'll be sure to open an issue about it to hit in the future. |
694f7d7 to
753313b
Compare
bec95f8 to
4810490
Compare
4810490 to
7500924
Compare
|
@callmehiphop ready to go. See the updated first post for the |
|
I think overall the code looks good, I'm not sure how else you would solve this problem. My only real critique is that the documentation for this seems like it would be easily overlooked. I know we generally don't highlight error handling in the doc examples, but what are your feelings on creating an additional example showing how to handle errors when dealing with a malformed image? |
|
Example added! |
lib/vision/index.js
Outdated
| * }); | ||
| * | ||
| * //- | ||
| * // To handle errors that occurred, check the length of the `errors` array. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
* vision: return errors * tests * test coverage fixer * tests * docs * add error handling example * elaborate error handling
Fixes #1333
To Dos
If the Vision API fails to annotate an image, it returns an
error(see https://cloud.google.com/vision/reference/rest/v1/images/annotate#annotateimageresponse) for each failed annotation. However, it will still annotate what it can.To add on errors to a single feature was a bit more complex: