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

Feature/only keep good data #22

Merged
merged 2 commits into from
Dec 16, 2022
Merged

Feature/only keep good data #22

merged 2 commits into from
Dec 16, 2022

Conversation

circlecube
Copy link
Member

Before storing data, also check that products and categories response contains key of data, since that's where the content should be and a hiive error returns only a message key.

Also, when the conditions are not met, the method will now return false so following processes will exit.

@circlecube circlecube self-assigned this Dec 12, 2022
@wpscholar
Copy link
Member

@circlecube While this is great, it wouldn't have prevented the issue we saw the other day.

The issue was with the products property. The response had a data property.

This was the payload we were seeing:

{
    "categories": {
        "data": [
            {
                "name": "featured",
                "priority": 100,
                "styles": null,
                "products_count": 6,
                "title": "Featured"
            },
            {
                "name": "services",
                "priority": 10,
                "styles": null,
                "products_count": 11,
                "title": "Services"
            },
            {
                "name": "ecommerce",
                "priority": 9,
                "styles": null,
                "products_count": 13,
                "title": "eCommerce"
            },
            {
                "name": "seo",
                "priority": 5,
                "styles": null,
                "products_count": 5,
                "title": "SEO"
            },
            {
                "name": "security",
                "priority": 3,
                "styles": null,
                "products_count": 6,
                "title": "Security"
            },
            {
                "name": "themes",
                "priority": 0,
                "styles": null,
                "products_count": 12,
                "title": "Themes"
            }
        ],
        "links": {
            "first": "https:\/\/hiive.cloud\/api\/marketplace\/v1\/products\/categories?brand=bluehost&per_page=60&page=1",
            "last": "https:\/\/hiive.cloud\/api\/marketplace\/v1\/products\/categories?brand=bluehost&per_page=60&page=1",
            "prev": null,
            "next": null
        },
        "meta": {
            "current_page": 1,
            "from": 1,
            "last_page": 1,
            "links": [
                {
                    "url": null,
                    "label": "« Previous",
                    "active": false
                },
                {
                    "url": "https:\/\/hiive.cloud\/api\/marketplace\/v1\/products\/categories?brand=bluehost&per_page=60&page=1",
                    "label": "1",
                    "active": true
                },
                {
                    "url": null,
                    "label": "Next »",
                    "active": false
                }
            ],
            "path": "https:\/\/hiive.cloud\/api\/marketplace\/v1\/products\/categories",
            "per_page": "60",
            "to": 6,
            "total": 6,
            "ttl": 86400
        }
    },
    "products": {
        "message": "Server Error"
    }
}

@wpscholar
Copy link
Member

Oh, I think these were both separate requests combined into one, right? So your check would apply to the products portion of the request not having a data property?

@circlecube
Copy link
Member Author

Oh, I think these were both separate requests combined into one, right? So your check would apply to the products portion of the request not having a data property?

Correct, I added one for products but I'm also adding one for categories endpoint too. So they both have the same check. The data is one field from the proper response. Looks like the error state only returned a message key. A proper response should include the data, meta and links keys but I figured just checking for data was enough and that expecting the data array to have a length of at least one might be a good addition, but felt a little overkill.

@circlecube circlecube requested a review from wpscholar December 13, 2022 14:27
@wpscholar
Copy link
Member

@circlecube It would be cool if we could define a JSON schema file for the expected responses from the Hiive and then could use those for testing on the Hiive as well as for validation of response data structures on the plugin side. Not sure how feasible that would actually be, but could guarantee that cached responses are always valid.

@circlecube
Copy link
Member Author

@circlecube It would be cool if we could define a JSON schema file for the expected responses from the Hiive and then could use those for testing on the Hiive as well as for validation of response data structures on the plugin side. Not sure how feasible that would actually be, but could guarantee that cached responses are always valid.

I like this idea. Maybe we create a task to help us get there. I don't want to expand this fix too much before getting it out.

@circlecube circlecube merged commit e750d15 into main Dec 16, 2022
@circlecube circlecube deleted the feature/only-keep-good-data branch December 16, 2022 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants