Skip to content

Commit 678c6c7

Browse files
committed
Add some extra error handling
1 parent eb029f4 commit 678c6c7

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gatsby-source-gcp-storage",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Gatsby source for reading files from GCP storage buckets",
55
"main": "index.js",
66
"scripts": {

readme.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ A Gatsby source plugin for sourcing data into your Gatsby application from file
55
[![](https://img.shields.io/npm/dm/gatsby-source-gcp-storage.svg)](https://www.npmjs.com/package/gatsby-source-gcp-storage)
66
[![CircleCI](https://circleci.com/gh/TheMagoo73/gatsby-source-gcp-storage/tree/master.svg?style=svg)](https://circleci.com/gh/TheMagoo73/gatsby-source-gcp-storage/tree/master)
77
[![codecov](https://codecov.io/gh/TheMagoo73/gatsby-source-gcp-storage/branch/master/graph/badge.svg)](https://codecov.io/gh/TheMagoo73/gatsby-source-gcp-storage)
8+
[![david](https://david-dm.org/themagoo73/gatsby-source-gcp-storage.svg)]()
89

910
The plugin creates `GCPFile` nodes from files in GCP Storage. It then uses the `gatsby-source-filesystem` to download a local copy of the files from GCP, and generate `File` nodes. The various "transformer" plugins can transform the File nodes into various other types of data e.g. `gatsby-transformer-json` transforms JSON files into JSON data nodes and `gatsby-transform-remark` transforms markdown files into `MarkdownRemark` nodes from which you can query and HTML representation of the markdown.
1011

src/gatsby-node.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,22 @@ exports.sourceNodes = async (api, pluginOptions) => {
4242
return
4343
}
4444

45-
const storage = new Storage({keyFilename: gcpTokenFile})
46-
const gcpBucket = storage.bucket(gcpBucketName)
45+
let files
4746

48-
let files = await gcpBucket.getFiles({directory: storageDirectory || `/`})
47+
try{
48+
const storage = new Storage({keyFilename: gcpTokenFile})
49+
const gcpBucket = storage.bucket(gcpBucketName)
50+
51+
files = await gcpBucket.getFiles({directory: storageDirectory || `/`})
52+
} catch(err) {
53+
reporter.panic(`
54+
55+
gatsby-source-gcp-storage: unable to access storage.
56+
57+
The GCP storage bucket/folder could not be accessed. Ensure that the bucker and path properties are correct, and the supplied SA account token has access
58+
59+
`)
60+
}
4961

5062
if(files[0].length < 1) {
5163
reporter.warn(`gatsby-source-gcp-storage: no files to process in ${gcpBucketName}/${storageDirectory}`)

0 commit comments

Comments
 (0)