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

"environment" is removed from header in getService() in version 1.8.x #47

Closed
zxm5010 opened this issue Feb 11, 2022 · 5 comments
Closed

Comments

@zxm5010
Copy link

zxm5010 commented Feb 11, 2022

We upgraded from 1.4 to 1.8 recently, and noticed an issue in recent 1.8.x versions that the following fetches after first one fails because of error: "error_message":"Failed to fetch entries. Please try again with valid parameters.","error_code":141,"errors":{"environment":["is required."]}}

I think this line causes an issue

this.headers.remove(Constants.ENVIRONMENT);

The "environment" gets removed from any getService call, which causes the issue.

We have a workaround now is to call setHeader every time before making fetch calls, please provide a fix for it. Thank you!

@zxm5010 zxm5010 changed the title "environment" is removed from header in getService() in version 1.8.1 "environment" is removed from header in getService() in version 1.8.x Feb 11, 2022
@ishaileshmishra
Copy link
Member

Hi, @zxm5010 thanks for writing us. We have removed the environment from the header. As per the documentation environment should go with Query Parameters see the documentation.

@zxm5010
Copy link
Author

zxm5010 commented Feb 14, 2022

Thanks @ishaileshmishra . We will add environment as a query param. So the environment passed into Stack constructor is no longer needed or used internally?

Second question:
we recently also notice after upgrading to version 1.8.x, stack object randomly returns {"error_message":"We can't find that Stack. Please try again.","error_code":109,"errors":{"api_key":["is not valid."]}} We have to reinitialize stack object again when encountering this. Any idea what change may cause it? It didn't happen in 1.4 for our live environment.

@ishaileshmishra
Copy link
Member

ishaileshmishra commented Feb 16, 2022

@zxm5010

1 - You don't need to add environment as a query param. we handle it internally.
2 - We are looking into it the issue you are getting api_key error.

We are trying to reproduce the said issue at our end

@zxm5010
Copy link
Author

zxm5010 commented Feb 17, 2022

@ishaileshmishra

1 - Quick clarification, we are always getting "error_message":"Failed to fetch entries. Please try again with valid parameters.","error_code":141,"errors":{"environment":["is required."]}} after the first fetch request, unless if we set header explicitly. I think there's something overwrites stack's context/header internally when we do fetches. Maybe it also relates to api_key error

For more context, we are fetching nested contents. And, nested fetches are called in the onCompletion method.

Example:

stack.contentType("root_content").query().find(
     new QueryResultsCallback() {
         public void onCompletion(ResponseType responseType, QueryResult queryResult, Error error) {
             if (error == null) {
                 //Success block
                 List<Entry> results = queryResult.getResultObjects();
                 for (Entry entry : results) {
                     JSONArray childrenContentRefs = entry.getJSONArray("children_content_refs");
                     for(int i = 0; i < childrenContentRefs.length(); i++) {
                         String uid = childrenContentRefs.getJSONObject(i).getString("uid");
                         Entry entry = stack.contentType("children_content").entry(uid);   
                         // ... logic dealing with children entry are truncated. 
                      }
                 }   
              } else {
                 //Error block
              }
         }
     }
)

Not sure if there's any behavior changes internally how the requests getting handled, but the logic mentioned above behaves fine in version 1.4.x, but start to behave unstable in 1.8.x

ishaileshmishra added a commit that referenced this issue Feb 23, 2022
This was referenced Mar 11, 2022
@ishaileshmishra
Copy link
Member

@zxm5010 Please update your contentstack-java dependency to v1.9.0,
Feel free to reopen the issue if your issue is not resolved.

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

No branches or pull requests

2 participants