Skip to content

Commit 4fc1237

Browse files
committed
fix(contentful): merge with master and improve network error detection
1 parent 85ed360 commit 4fc1237

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

packages/gatsby-source-contentful/src/__tests__/fetch-network-errors.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,17 @@ describe(`fetch-retry`, () => {
5757
.reply(200, { items: [{ code: `en`, default: true }] })
5858
// Sync
5959
.get(
60-
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=100`
60+
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=1000`
6161
)
6262
.times(1)
6363
.replyWithError({ code: `ETIMEDOUT` })
6464
.get(
65-
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=100`
65+
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=1000`
6666
)
6767
.reply(200, { items: [] })
6868
// Content types
6969
.get(
70-
`/spaces/${options.spaceId}/environments/master/content_types?skip=0&limit=100&order=sys.createdAt`
70+
`/spaces/${options.spaceId}/environments/master/content_types?skip=0&limit=1000&order=sys.createdAt`
7171
)
7272
.reply(200, { items: [] })
7373

@@ -90,7 +90,7 @@ describe(`fetch-retry`, () => {
9090
.reply(200, { items: [{ code: `en`, default: true }] })
9191
// Sync
9292
.get(
93-
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=100`
93+
`/spaces/${options.spaceId}/environments/master/sync?initial=true&limit=1000`
9494
)
9595
.times(3)
9696
.reply(

packages/gatsby-source-contentful/src/__tests__/fetch.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ describe(`Displays troubleshooting tips and detailed plugin options on contentfu
255255
it(`API 404 response handling`, async () => {
256256
mockClient.getLocales.mockImplementation(() => {
257257
const err = new Error(`error`)
258-
err.responseData = { status: 404 }
258+
err.status = 404
259259
throw err
260260
})
261261

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

packages/gatsby-source-contentful/src/fetch.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ module.exports = async function contentfulFetch({
159159
sourceMessage: `We couldn't make a secure connection to your contentful space. Please check if you have any self-signed SSL certificates installed.`,
160160
},
161161
})
162-
} else if (e.responseData) {
163-
if (e.responseData.status === 404) {
162+
} else if (e.status) {
163+
if (e.status === 404) {
164164
// host and space used to generate url
165165
details = `Endpoint not found. Check if ${chalk.yellow(
166166
`host`
@@ -169,7 +169,7 @@ module.exports = async function contentfulFetch({
169169
host: `Check if setting is correct`,
170170
spaceId: `Check if setting is correct`,
171171
}
172-
} else if (e.responseData.status === 401) {
172+
} else if (e.status === 401) {
173173
// authorization error
174174
details = `Authorization error. Check if ${chalk.yellow(
175175
`accessToken`
@@ -222,7 +222,7 @@ ${formatPluginOptionsForCLI(pluginConfig.getOriginalPluginOptions(), errors)}`,
222222
} catch (e) {
223223
// Back off page limit if responses content length exceeds Contentfuls limits.
224224
if (
225-
e.responseData.data.message.includes(`Response size too big`) &&
225+
e.response?.data?.message.includes(`Response size too big`) &&
226226
currentPageLimit > 1
227227
) {
228228
lastCurrentPageLimit = currentPageLimit

0 commit comments

Comments
 (0)