fix: handle invalid Algolia keys gracefully in dev (#37088)

Invalid keys throw an error in production, but just cause invalid
PropTypes and build warnings in development.
This commit is contained in:
Oliver Eyton-Williams
2019-10-08 10:19:43 +02:00
committed by mrugesh
parent 4889e0fdc6
commit e72855dad3
4 changed files with 28 additions and 7 deletions

View File

@ -1,4 +1,4 @@
require('dotenv').config();
const env = require('../config/env');
const { createFilePath } = require('gatsby-source-filesystem');
@ -39,7 +39,18 @@ exports.onCreateNode = function onCreateNode({ node, actions, getNode }) {
}
};
exports.createPages = function createPages({ graphql, actions }) {
exports.createPages = function createPages({ graphql, actions, reporter }) {
if (!env.algoliaAPIKey || !env.algoliaAppId) {
if (process.env.FREECODECAMP_NODE_ENV === 'production') {
throw new Error(
'Algolia App id and API key are required to start the client!'
);
} else {
reporter.info(
'Algolia keys missing or invalid. Required for search to yield results.'
);
}
}
const { createPage } = actions;
return new Promise((resolve, reject) => {