Skip to content

Commit fb38f8a

Browse files
authored
fix(gatsby-source-contentful): validation with environment (#29228)
1 parent 7c38997 commit fb38f8a

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

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

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,28 @@ exports.setFieldsOnGraphQLNodeType = require(`./extend-node-type`).extendNodeTyp
2929
const validateContentfulAccess = async pluginOptions => {
3030
if (process.env.NODE_ENV === `test`) return undefined
3131

32-
await fetch(`https://${pluginOptions.host}/spaces/${pluginOptions.spaceId}`, {
33-
headers: {
34-
Authorization: `Bearer ${pluginOptions.accessToken}`,
35-
"Content-Type": `application/json`,
36-
},
37-
})
32+
await fetch(
33+
`https://${pluginOptions.host}/spaces/${pluginOptions.spaceId}/environments/${pluginOptions.environment}/content_types`,
34+
{
35+
headers: {
36+
Authorization: `Bearer ${pluginOptions.accessToken}`,
37+
"Content-Type": `application/json`,
38+
},
39+
}
40+
)
3841
.then(res => res.ok)
3942
.then(ok => {
40-
if (!ok)
41-
throw new Error(
42-
`Cannot access Contentful space "${maskText(
43-
pluginOptions.spaceId
44-
)}" with access token "${maskText(
45-
pluginOptions.accessToken
46-
)}". Make sure to double check them!`
47-
)
43+
if (!ok) {
44+
let errorMessage = `Cannot access Contentful space "${maskText(
45+
pluginOptions.spaceId
46+
)}" on environment "${
47+
pluginOptions.environment
48+
} with access token "${maskText(
49+
pluginOptions.accessToken
50+
)}". Make sure to double check them!`
51+
52+
throw new Error(errorMessage)
53+
}
4854
})
4955

5056
return undefined

0 commit comments

Comments
 (0)