Skip to content

Commit

Permalink
fix(contentful): merge with master and improve network error detection
Browse files Browse the repository at this point in the history
  • Loading branch information
axe312ger committed Mar 29, 2021
1 parent 85ed360 commit 4fc1237
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Expand Up @@ -57,17 +57,17 @@ describe(`fetch-retry`, () => {
.reply(200, { items: [{ code: `en`, default: true }] })
// Sync
.get(
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=100`
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=1000`
)
.times(1)
.replyWithError({ code: `ETIMEDOUT` })
.get(
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=100`
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=1000`
)
.reply(200, { items: [] })
// Content types
.get(
`/spaces/${options.spaceId}/environments/master/content_types?skip=0&limit=100&order=sys.createdAt`
`/spaces/${options.spaceId}/environments/master/content_types?skip=0&limit=1000&order=sys.createdAt`
)
.reply(200, { items: [] })

Expand All @@ -90,7 +90,7 @@ describe(`fetch-retry`, () => {
.reply(200, { items: [{ code: `en`, default: true }] })
// Sync
.get(
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=100`
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=1000`
)
.times(3)
.reply(
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-source-contentful/src/__tests__/fetch.js
Expand Up @@ -255,7 +255,7 @@ describe(`Displays troubleshooting tips and detailed plugin options on contentfu
it(`API 404 response handling`, async () => {
mockClient.getLocales.mockImplementation(() => {
const err = new Error(`error`)
err.responseData = { status: 404 }
err.status = 404
throw err
})

Expand Down Expand Up @@ -295,7 +295,7 @@ describe(`Displays troubleshooting tips and detailed plugin options on contentfu
it(`API authorization error handling`, async () => {
mockClient.getLocales.mockImplementation(() => {
const err = new Error(`error`)
err.responseData = { status: 401 }
err.status = 401
throw err
})

Expand Down
8 changes: 4 additions & 4 deletions packages/gatsby-source-contentful/src/fetch.js
Expand Up @@ -159,8 +159,8 @@ module.exports = async function contentfulFetch({
sourceMessage: `We couldn't make a secure connection to your contentful space. Please check if you have any self-signed SSL certificates installed.`,
},
})
} else if (e.responseData) {
if (e.responseData.status === 404) {
} else if (e.status) {
if (e.status === 404) {
// host and space used to generate url
details = `Endpoint not found. Check if ${chalk.yellow(
`host`
Expand All @@ -169,7 +169,7 @@ module.exports = async function contentfulFetch({
host: `Check if setting is correct`,
spaceId: `Check if setting is correct`,
}
} else if (e.responseData.status === 401) {
} else if (e.status === 401) {
// authorization error
details = `Authorization error. Check if ${chalk.yellow(
`accessToken`
Expand Down Expand Up @@ -222,7 +222,7 @@ ${formatPluginOptionsForCLI(pluginConfig.getOriginalPluginOptions(), errors)}`,
} catch (e) {
// Back off page limit if responses content length exceeds Contentfuls limits.
if (
e.responseData.data.message.includes(`Response size too big`) &&
e.response?.data?.message.includes(`Response size too big`) &&
currentPageLimit > 1
) {
lastCurrentPageLimit = currentPageLimit
Expand Down

0 comments on commit 4fc1237

Please sign in to comment.