Skip to content

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

Closed

Description

@zxm5010

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!

Activity

  1. 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[/+] on Feb 11, 2022
  2. ishaileshmishra commented on Feb 14, 2022

    @ishaileshmishra
    Contributor

    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.

  3. zxm5010 commented on Feb 14, 2022

    @zxm5010
    Author

    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.

  4. ishaileshmishra commented on Feb 16, 2022

    @ishaileshmishra
    Contributor

    @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

  5. zxm5010 commented on Feb 17, 2022

    @zxm5010
    Author

    @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

  6. added a commit that references this issue on Feb 23, 2022
  7. ishaileshmishra commented on Mar 16, 2022

    @ishaileshmishra
    Contributor

    @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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions