-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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(gatsby-source-contentful): Improve network error handling #30257
fix(gatsby-source-contentful): Improve network error handling #30257
Conversation
axe312ger
commented
Mar 15, 2021
•
edited
Loading
edited
- improve sync progress & error logging
- reintroduce retry logic from Contentful SDK
- allow setting of any value of Contentful SDK again (VERY helpful for tests and debugging aka setting request headers)
- add tests
495f495
to
8946b74
Compare
Can you elaborate on "allow setting of any value of Contentful SDK again (VERY helpful for tests and debugging aka setting request headers)". Why would you want to augment it, instead of adding these values to the plugin itself? Why don't we support a retry option, ...? You'll also need to update plugin validation in gatsby-node |
@wardpeet: the Contentful SDK allows a lot of options, some might be relevant in rare use cases. Most people won't need this at all. Keeping these in sync with Gatsby configuration is extra work we can avoid. https://github.com/contentful/contentful.js/#configuration This PR needs it to speed up the tests, otherwise it would retry 30seconds in one test. Also:
|
db291ba
to
6da14b6
Compare
@@ -181,6 +179,12 @@ Number of entries to retrieve from Contentful at a time. Due to some technical l | |||
|
|||
Number of workers to use when downloading Contentful assets. Due to technical limitations, opening too many concurrent requests can cause stalled downloads. If you encounter this issue you can set this param to a lower number than 50, e.g 25. | |||
|
|||
**`contentfulClientConfig`** [object][optional] [default: `{}`] | |||
|
|||
Additional config which will get passed to [Contentfuls JS SDK](https://github.com/contentful/contentful.js#configuration). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add retryLimit
in the SDK readme?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, but if you do, pls make sure to add the other potential missing config options there as well :)
Co-authored-by: Ward Peeters <ward@coding-tech.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some minor comments, I'm not 100% confident on the pluginOptions part as we don't have tests for it. We can test when we merge this and try out the @next package.
const createContentfulErrorMessage = e => { | ||
// If we got a response, it is very likely that it is a Contentful API error. | ||
if (e.response) { | ||
let parsedContentfulErrorData = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't set empty object here, null is fine
let parsedContentfulErrorData = {} | |
let parsedContentfulErrorData = null |
if (typeof parsedContentfulErrorData !== `object`) { | ||
throw new Error() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON.parse('string') will throw an error when it's not parsable. Unsure what you're trying to guard against.
|
||
let errorMessage = [ | ||
// Generic error values | ||
e.code && `${e.code}`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e.code && `${e.code}`, | |
e.code && String(e.code), |
@wardpeet I (re)implemented I need this to be merged into v4 of gatsby-source-contentful and that version has feature freeze due to Gatsby v3 release (has it?) Alternatively I could directly implement |
Alternative #2: Remove the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! THank you!
Co-authored-by: Ward Peeters <ward@coding-tech.com> (cherry picked from commit c1ac5e4)
Co-authored-by: Ward Peeters <ward@coding-tech.com> (cherry picked from commit c1ac5e4)
Co-authored-by: Ward Peeters <ward@coding-tech.com> (cherry picked from commit c1ac5e4)