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

Gatsby-4: Changing environment throws an error when sourcing #117

Closed
psykzz opened this issue Dec 14, 2021 · 13 comments
Closed

Gatsby-4: Changing environment throws an error when sourcing #117

psykzz opened this issue Dec 14, 2021 · 13 comments
Assignees

Comments

@psykzz
Copy link

psykzz commented Dec 14, 2021

Once setup, if you change environment (but keeping the same key) you will get the following error.

{
  error_message: 'Failed to fetch items. Please try again with valid parameters.',
  error_code: 141,
  errors: { access_token: [ 'environment or access token is not matched.' ] }
}

Looks like we just need to include the environment + api_key in the cache key.

@vkalta
Copy link
Contributor

vkalta commented Dec 14, 2021

@psykzz Thanks for reporting this issue. I will check and get back to you asap.

@vkalta
Copy link
Contributor

vkalta commented Jan 14, 2022

@psykzz Can you share the steps to reproduce this issue?

@psykzz
Copy link
Author

psykzz commented Jan 14, 2022

  • Setup a contentstack stack with two environments, A + B.

  • Setup a Gatsby site building data from stack B.

  • Change the access_token and environement from A -> B.

  • Observe the issue

@vkalta
Copy link
Contributor

vkalta commented Jan 17, 2022

Thanks @psykzz for sharing the steps. Will check this ASAP.

@psykzz
Copy link
Author

psykzz commented Aug 15, 2022

Any updates on this issue? @vkalta

@vkalta
Copy link
Contributor

vkalta commented Aug 15, 2022

@abhishek305 Can you please check this and update @psykzz ?

@psykzz
Copy link
Author

psykzz commented Aug 15, 2022

More details and a potential fix can be found in #116 (comment)

@abhishek305
Copy link
Contributor

Hey @psykzz,
I will try to reproduce this issue on my end and will update you soon.
Thanks again

@abhishek305
Copy link
Contributor

@abhishek305 Can you please check this and update @psykzz ?

Yes will check

@abhishek305
Copy link
Contributor

  • Setup a contentstack stack with two environments, A + B.
  • Setup a Gatsby site building data from stack B.
  • Change the access_token and environement from A -> B.
  • Observe the issue

Hey @psykzz,

Could please elaborate there seems to be some confusion in step 3 are you talking about setting up 2 stacks or a stack with two environments and also the gatsby site sourcing from 2 stacks?

@psykzz
Copy link
Author

psykzz commented Aug 16, 2022

So I have a stack with multiple environments.
I setup and run against environment A, and everything builds fine.

In this case i needed to provide the following configuration

{
  api_key: "stack-api-key"
  delivery_token: "environment-a-delivery-token"
  environment_name: "environment-a"
}

If i then swap to environment B. I replace my config with

{
  api_key: "stack-api-key"
  delivery_token: "environment-b-delivery-token"
  environment_name: "environment-b"
}

After running the 2nd time, i get

{
  error_message: 'Failed to fetch items. Please try again with valid parameters.',
  error_code: 141,
  errors: { access_token: [ 'environment or access token is not matched.' ] }
}

This is because i believe the cached data is only keyed by the api_key and so changing the delivery token attempts to use the old cache, which in this case is wrong, leading to the error message.

@abhishek305
Copy link
Contributor

So I have a stack with multiple environments. I setup and run against environment A, and everything builds fine.

In this case i needed to provide the following configuration

{
  api_key: "stack-api-key"
  delivery_token: "environment-a-delivery-token"
  environment_name: "environment-a"
}

If i then swap to environment B. I replace my config with

{
  api_key: "stack-api-key"
  delivery_token: "environment-b-delivery-token"
  environment_name: "environment-b"
}

After running the 2nd time, i get

{
  error_message: 'Failed to fetch items. Please try again with valid parameters.',
  error_code: 141,
  errors: { access_token: [ 'environment or access token is not matched.' ] }
}

This is because i believe the cached data is only keyed by the api_key and so changing the delivery token attempts to use the old cache, which in this case is wrong, leading to the error message.

Hi @psykzz,
I tried to reproduce the error from the steps you've given but was unable to reproduce this on my end.
Steps I performed:

  • Both develop & build command (without removing cache)
  • Changed environments & delivery token simultaneously(keeping the api-key same & not removing the cached data)

Could you please update the source plugin version and try it once also if possible could you share a few details?

let me know what is observed after the update
Thanks !!

@Contentstack-AnkitaD
Copy link
Contributor

Quick update:
No activity was observed in this issue for more than a 2 years, closing now.
Reopen if required.
Thanks !!

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

4 participants