CodeSandbox-https://codesandbox.io/s/jj597mrvmw
我从外部 API 返回到我的 GatsbyJS / ReactJS 网站的某些数据有问题。
更具体地说,问题似乎是在 GraphQL 查询上使用API gatsby-image
使用gatsby-plugin-sharp
和...GatsbyImageSharpFluid
处理图像时出现的。
从1000幅图像来看,似乎只有1幅图像很麻烦,并返回错误
Errors:
icc_transform: no input profile
vips_colourspace: no known route from 'cmyk' to 'srgb'
我可以过滤掉该图像,但担心将来的图像作为API更新可能会导致相同的问题。
我如何
sharp
所显示的错误,以便可以处理图像吗?或者,filter
期间返回此错误的createRemoteFileNode
个图像,或catch (error)
中跳过麻烦的图像,或createRemoteFileNode
中的 gatsby-node.js
与
exports.sourceNodes = async ({ actions, store, cache, createNodeId }) => {
const { createNode, createNodeField } = actions;
const { data } = await axios.get(API_URI);
for (const event of data._embedded.events) {
let fileNode;
let output = [];
let filterResults = event.images.filter(e => e.width >= 1900);
output.push(...filterResults);
try {
fileNode = await createRemoteFileNode({
url: output[0].url,
cache,
store,
createNode,
createNodeId,
});
await createNodeField({
node: fileNode,
name: 'EventImage',
value: 'true'
});
await createNodeField({
node: fileNode,
name: 'name',
value: event.name
});
} catch (error) {
console.warn('error creating node', error);
}
}
};