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

Code before:
          } ${response.response.statusText} (${createMetadataLog(
            response.response
          )})`
        )
        let errorMessage = `${response.response.status} ${response.response.statusText}`
        if (response.response?.data?.message) {
          errorMessage += `\n\n${response.response.data.message}`
        }
        const contentfulApiError = new Error(errorMessage)
        // Special response naming to ensure the error object is not touched by
        // https://github.com/contentful/contentful.js/commit/41039afa0c1462762514c61458556e6868beba61
        contentfulApiError.responseData = response.response
        contentfulApiError.request = response.request
        contentfulApiError.config = response.config

        throw contentfulApiError
      }

      reporter.verbose(
        `${response.config.method} /${response.config.url}: ${
          response.status
        } ${response.statusText} (${createMetadataLog(response)})`
      )
    },
  }

  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.`,
        },

Review comment (suggestion):
Note: .verbose is not a noop if you don't use verbose mode. For non-trivial arguments, like whatever `createMetadataLog()` does, check `if (process.env.gatsby_log_level === `verbose`) {`


Code after:
        reporter.verbose(
          `${response.config.method} /${response.config.url}: ${
            response.response.status
          } ${response.response.statusText} (${createMetadataLog(
            response.response
          )})`
        )
        let errorMessage = `${response.response.status} ${response.response.statusText}`
        if (response.response?.data?.message) {
          errorMessage += `\n\n${response.response.data.message}`
        }
        const contentfulApiError = new Error(errorMessage)
        // Special response naming to ensure the error object is not touched by
        // https://github.com/contentful/contentful.js/commit/41039afa0c1462762514c61458556e6868beba61
        contentfulApiError.responseData = response.response
        contentfulApiError.request = response.request
        contentfulApiError.config = response.config

        throw contentfulApiError
      }

      reporter.verbose(
        `${response.config.method} /${response.config.url}: ${
          response.status
        } ${response.statusText} (${createMetadataLog(response)})`
      )
    },
  }

  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