Repository: gatsbyjs/gatsby
File: packages/gatsby/cache-dir/loader.js (JavaScript)

Code before:
    return findMatchPath(rawPath)
  }

  // TODO check all uses of this and whether they use undefined for page resources not exist
  loadPage(rawPath) {
    const pagePath = findPath(rawPath)
    if (this.pageDb.has(pagePath)) {
      const page = this.pageDb.get(pagePath)
      return Promise.resolve(page.payload)
    }

    if (this.inFlightDb.has(pagePath)) {
      return this.inFlightDb.get(pagePath)
    }

    const inFlightPromise = Promise.all([
      this.loadAppData(),
      this.loadPageDataJson(pagePath),
    ]).then(allData => {
      const result = allData[1]
      if (result.status === PageResourceStatus.Error) {
        return {
          status: PageResourceStatus.Error,
        }
      }

      let pageData = result.payload
      const { componentChunkName, staticQueryHashes = [] } = pageData

      let finalResult = {}

      const componentChunkPromise = this.loadComponent(componentChunkName).then(
        component => {
          finalResult.createdAt = new Date()
          let pageResources
          if (!component) {
            finalResult.status = PageResourceStatus.Error
          } else {
            finalResult.status = PageResourceStatus.Success
            if (result.notFound === true) {
              finalResult.notFound = true
            }
            pageData = Object.assign(pageData, {
              webpackCompilationHash: allData[0]
                ? allData[0].webpackCompilationHash
                : ``,
            })
            pageResources = toPageResources(pageData, component)
          }
          // undefined if final result is an error
          return pageResources

Review comment (suggestion):
```suggestion
      const result = allData[1]
      const { status } = result
      if (status === PageResourceStatus.Error) {
        return { status } 
      }
```

Code after:
  findMatchPath(rawPath) {
    return findMatchPath(rawPath)
  }

  // TODO check all uses of this and whether they use undefined for page resources not exist
  loadPage(rawPath) {
    const pagePath = findPath(rawPath)
    if (this.pageDb.has(pagePath)) {
      const page = this.pageDb.get(pagePath)
      return Promise.resolve(page.payload)
    }

    if (this.inFlightDb.has(pagePath)) {
      return this.inFlightDb.get(pagePath)
    }

    const inFlightPromise = Promise.all([
      this.loadAppData(),
      this.loadPageDataJson(pagePath),
    ]).then(allData => {
      const result = allData[1]
      if (result.status === PageResourceStatus.Error) {
        return {
          status: PageResourceStatus.Error,
        }
      }

      let pageData = result.payload
      const { componentChunkName, staticQueryHashes = [] } = pageData

      const finalResult = {}

      const componentChunkPromise = this.loadComponent(componentChunkName).then(
        component => {
          finalResult.createdAt = new Date()
          let pageResources
          if (!component) {
            finalResult.status = PageResourceStatus.Error
          } else {
            finalResult.status = PageResourceStatus.Success
            if (result.notFound === true) {
              finalResult.notFound = true
            }
            pageData = Object.assign(pageData, {
              webpackCompilationHash: allData[0]
                ? allData[0].webpackCompilationHash
                : ``,
            })
            pageResources = toPageResources(pageData, component)
          }
          // undefined if final result is an error