openfoodfacts / openfoodfacts-nodejs

Official Node package for Open Food Facts
https://openfoodfacts.github.io/openfoodfacts-nodejs/
Apache License 2.0
148 stars 27 forks source link

feat: add support for Nutri-Patrol API #534

Closed bengeois closed 3 weeks ago

bengeois commented 1 month ago

What

Nutripatrol API wrapper

Fix https://github.com/openfoodfacts/openfoodfacts-nodejs/issues/520

VaiTon commented 1 month ago

Hey @bengeois, thanks for your work! We don't usually throw errors. Instead we return them as a Union. Can we please also do that in this section of the API?

See https://github.com/openfoodfacts/openfoodfacts-nodejs/blob/71b84960bd96da541d02470a0ecfa35b01cfb907/src/folksonomy.ts#L112 for reference.

sonarcloud[bot] commented 1 month ago

Quality Gate Passed Quality Gate passed

Issues
11 New issues
0 Accepted issues

Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

bengeois commented 1 month ago

Hey @VaiTon , thanks for your feedback!

Initially, I was using catch blocks to separate error handling logic from the standard flow. However, I've refactored the code as requested to align with the existing approach used in other wrappers, where errors are returned as a Union.

Additionally, I’ve introduced a NutriPatrolError to provide more detailed information, such as the statusCode. This allows us to maintain useful error details that would otherwise be lost if we didn't include them.

Let me know if you have any other thoughts!

teolemon commented 3 weeks ago

Thanks @bengeois and congratulations on this first feature 👌