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

Update unit testing to main #22

Merged
merged 3 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions server/controllers/products.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ async function searchAndDisplayProducts(req, res) {
);
}

// // any errors that slipped through propagation
// if (productData.error) {
// throw productData.error;
// }
// any errors that slipped through propagation
if (productData.error) {
throw productData.error;
}

if (Object.keys(productData).length === 0) {
throw new Error("Products not found in OpenFoodFacts database");
Expand Down
8 changes: 3 additions & 5 deletions server/models/products.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,16 @@ ProductModel.fetchOFFProductByBarcode = async function (barcode) {

if (!response.data || !response.data.product) {
// Return an empty object if no products found
return {};
throw new Error("Products not found in OpenFoodFacts database");
}

return response.data.product;
} catch (error) {
if (error.response && error.response.status === 500) {
// Return specific error message for rate limit issues from OpenFoodFacts
throw new Error("OpenFoodFacts API rate limit reached");
} else if (error.response && error.reponse.status === 404) {
// Return specific error message for product not found
throw new Error("Products not found in OpenFoodFacts database.");
} else throw error;
// Return product not found error
} else throw new Error("Products not found in OpenFoodFacts database");
}
};

Expand Down
Loading