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

fix: unit test value + better json decode #865

Merged

Conversation

monsieurtanuki
Copy link
Contributor

@monsieurtanuki monsieurtanuki commented Jan 12, 2024

What

  • Fixed a unit test value
  • Improved the json decoding when the server is down. Something like
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>� Service Downtime Notification - Open Food Facts �</title>
    <style>

image

image

Impacted files

  • api_get_product_test.dart: updated expected value
  • http_helper.dart: handled the <!DOCTYPE html> returned from the server when jsondecoding

Impacted files:
* `api_get_product_test.dart`
* `http_helper.dart`
Copy link
Member

@M123-dev M123-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also integrate this into the requests. Seeing multiple issues of format exception due to html responses in sentry

@monsieurtanuki monsieurtanuki merged commit 565c0fa into openfoodfacts:master Jan 12, 2024
3 checks passed
@monsieurtanuki
Copy link
Contributor Author

Thank you @M123-dev for your review!

We could also integrate this into the requests. Seeing multiple issues of format exception due to html responses in sentry

I'm not sure what you mean and/or how we should proceed, then, as we return a Product or throw an exception.
If we want to always return something, we should return a "meta-product" that contains a nullable product and a nullable "exception".
What is currently implemented is that almost every request uses a custom json decode method, that handles the potential <html> returned. In this PR I added a case in the common custom json decode method, therefore I think we should be fine from now on.
Feel free to open an issue if I've misunderstood your use-case.

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

Successfully merging this pull request may close these issues.

2 participants