Repository: gatsbyjs/gatsby
File: packages/gatsby-source-contentful/src/fetch.js (JavaScript)

Code before:

  const client = contentful.createClient(contentfulClientOptions)

  // The sync API puts the locale in all fields in this format { fieldName:
  // {'locale': value} } so we need to get the space and its default local.
  //
  // We'll extend this soon to support multiple locales.
  let space
  let locales
  let defaultLocale = `en-US`
  try {
    reporter.verbose(`Fetching default locale`)
    space = await client.getSpace()
    let contentfulLocales = await client
      .getLocales()
      .then(response => response.items)
    defaultLocale = _.find(contentfulLocales, { default: true }).code
    locales = contentfulLocales.filter(pluginConfig.get(`localeFilter`))
    if (locales.length === 0) {
      reporter.panic({
        id: CODES.LocalesMissing,
        context: {
          sourceMessage: `Please check if your localeFilter is configured properly. Locales '${_.join(
            contentfulLocales.map(item => item.code),
            `,`
          )}' were found but were filtered down to none.`,
        },
      })
    }
    reporter.verbose(`Default locale is: ${defaultLocale}`)
  } catch (e) {
    let details
    let errors
    if (e.code === `ENOTFOUND`) {
      details = `You seem to be offline`
    } else if (e.code === `SELF_SIGNED_CERT_IN_CHAIN`) {
      reporter.panic(
        {
          id: CODES.SelfSignedCertificate,
          context: {
            sourceMessage: `We couldn't make a secure connection to your contentful space. Please check if you have any self-signed SSL certificates installed.`,
          },
        },
        e
      )
    } else if (e.response) {
      if (e.response.status === 404) {
        // host and space used to generate url
        details = `Endpoint not found. Check if ${chalk.yellow(
          `host`
        )} and ${chalk.yellow(`spaceId`)} settings are correct`

Review comment (suggestion):
No need for lodash here

```suggestion
          sourceMessage: `Please check if your localeFilter is configured properly. Locales '${
            contentfulLocales.map(item => item.code).join(`,`)
          }' were found but were filtered down to none.`,
```

Code after:

  const client = contentful.createClient(contentfulClientOptions)

  // The sync API puts the locale in all fields in this format { fieldName:
  // {'locale': value} } so we need to get the space and its default local.
  //
  // We'll extend this soon to support multiple locales.
  let space
  let locales
  let defaultLocale = `en-US`
  try {
    reporter.verbose(`Fetching default locale`)
    space = await client.getSpace()
    let contentfulLocales = await client
      .getLocales()
      .then(response => response.items)
    defaultLocale = _.find(contentfulLocales, { default: true }).code
    locales = contentfulLocales.filter(pluginConfig.get(`localeFilter`))
    if (locales.length === 0) {
      reporter.panic({
        id: CODES.LocalesMissing,
        context: {
          sourceMessage: `Please check if your localeFilter is configured properly. Locales '${contentfulLocales
            .map(item => item.code)
            .join(`,`)}' were found but were filtered down to none.`,
        },
      })
    }
    reporter.verbose(`Default locale is: ${defaultLocale}`)
  } catch (e) {
    let details
    let errors
    if (e.code === `ENOTFOUND`) {
      details = `You seem to be offline`
    } else if (e.code === `SELF_SIGNED_CERT_IN_CHAIN`) {
      reporter.panic(
        {
          id: CODES.SelfSignedCertificate,
          context: {
            sourceMessage: `We couldn't make a secure connection to your contentful space. Please check if you have any self-signed SSL certificates installed.`,
          },
        },
        e
      )
    } else if (e.response) {
      if (e.response.status === 404) {
        // host and space used to generate url
        details = `Endpoint not found. Check if ${chalk.yellow(
          `host`
        )} and ${chalk.yellow(`spaceId`)} settings are correct`
        errors = {