philhawksworth / netlify-plugin-form-submissions

Fetch all submissions made to Netlify Forms in your site and stash them as JSON files before your build runs making the data available to your static site generator at build time.
MIT License
2 stars 1 forks source link

Handle cases where API requests does not return JSON #1

Closed ehmicky closed 4 years ago

ehmicky commented 4 years ago

In the following build, the main API request is not returning JSON:

11:43:07 PM: Build ready to start
11:43:09 PM: build-image version: ca811f47d4c1cbd1812d1eb6ecb0c977e86d1a1d
11:43:09 PM: build-image tag: v3.3.20
11:43:09 PM: buildbot version: 78b5536ab4f742c26705d3e953381b9cde6e22ef
11:43:09 PM: Fetching cached dependencies
11:43:10 PM: Failed to fetch cache, continuing with build
11:43:10 PM: Starting to prepare the repo for build
11:43:10 PM: No cached dependencies found. Cloning fresh repo
11:43:10 PM: git clone https://github.com/gregcanter/jamstack-comments-engine
11:43:11 PM: Preparing Git Reference refs/heads/master
11:43:12 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'src/functions' versus '' in the Netlify UI
11:43:12 PM: Starting build script
11:43:12 PM: Installing dependencies
11:43:12 PM: Python version set to 2.7
11:43:13 PM: v12.18.0 is already installed.
11:43:14 PM: Now using node v12.18.0 (npm v6.14.4)
11:43:14 PM: Started restoring cached build plugins
11:43:14 PM: Finished restoring cached build plugins
11:43:14 PM: Attempting ruby version 2.7.1, read from environment
11:43:15 PM: Using ruby version 2.7.1
11:43:15 PM: Using PHP version 5.6
11:43:15 PM: 5.2 is already installed.
11:43:15 PM: Using Swift version 5.2
11:43:15 PM: Started restoring cached node modules
11:43:15 PM: Finished restoring cached node modules
11:43:15 PM: Installing NPM modules using NPM version 6.14.4
11:43:29 PM: > node-sass@4.14.1 install /opt/build/repo/node_modules/node-sass
11:43:29 PM: > node scripts/install.js
11:43:29 PM: Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/linux-x64-72_binding.node
11:43:30 PM: Download complete
11:43:30 PM: Binary saved to /opt/build/repo/node_modules/node-sass/vendor/linux-x64-72/binding.node
11:43:30 PM: Caching binary to /opt/buildhome/.npm/node-sass/4.14.1/linux-x64-72_binding.node
11:43:30 PM: > core-js@2.6.11 postinstall /opt/build/repo/node_modules/core-js
11:43:30 PM: > node -e "try{require('./postinstall')}catch(e){}"
11:43:30 PM: > ejs@2.7.4 postinstall /opt/build/repo/node_modules/ejs
11:43:30 PM: > node ./postinstall.js
11:43:30 PM: > node-sass@4.14.1 postinstall /opt/build/repo/node_modules/node-sass
11:43:30 PM: > node scripts/build.js
11:43:30 PM: Binary found at /opt/build/repo/node_modules/node-sass/vendor/linux-x64-72/binding.node
11:43:30 PM: Testing binary
11:43:30 PM: Binary is fine
11:43:31 PM: npm WARN jamstack-comments-example@2.0.0 No repository field.
11:43:31 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
11:43:31 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
11:43:31 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/chokidar/node_modules/fsevents):
11:43:31 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
11:43:31 PM: added 856 packages from 571 contributors and audited 861 packages in 14.658s
11:43:31 PM: 23 packages are looking for funding
11:43:31 PM:   run `npm fund` for details
11:43:31 PM: found 4 vulnerabilities (3 low, 1 high)
11:43:31 PM:   run `npm audit fix` to fix them, or `npm audit` for details
11:43:31 PM: NPM modules installed
11:43:31 PM: Started restoring cached go cache
11:43:31 PM: Finished restoring cached go cache
11:43:31 PM: go version go1.14.4 linux/amd64
11:43:32 PM: go version go1.14.4 linux/amd64
11:43:32 PM: Installing missing commands
11:43:32 PM: Verify run directory
11:43:33 PM: ​
11:43:33 PM: ┌─────────────────────────────┐
11:43:33 PM: │        Netlify Build        │
11:43:33 PM: └─────────────────────────────┘
11:43:33 PM: ​
11:43:33 PM: ❯ Version
11:43:33 PM:   @netlify/build 2.0.27
11:43:33 PM: ​
11:43:33 PM: ❯ Flags
11:43:33 PM:   deployId: 5f08e0eba638bf0007cdb7b9
11:43:33 PM:   mode: buildbot
11:43:33 PM: ​
11:43:33 PM: ❯ Current directory
11:43:33 PM:   /opt/build/repo
11:43:33 PM: ​
11:43:33 PM: ❯ Config file
11:43:33 PM:   /opt/build/repo/netlify.toml
11:43:33 PM: ​
11:43:33 PM: ❯ Context
11:43:33 PM:   production
11:43:33 PM: ​
11:43:33 PM: ❯ Loading plugins
11:43:33 PM:    - netlify-plugin-form-submissions@0.1.3 from netlify.toml and package.json
11:43:34 PM: ​
11:43:34 PM: ┌────────────────────────────────────────────────────────────┐
11:43:34 PM: │ 1. onPreBuild command from netlify-plugin-form-submissions │
11:43:34 PM: └────────────────────────────────────────────────────────────┘
11:43:34 PM: ​
11:43:34 PM: ​
11:43:34 PM: ┌─────────────────────────────────────────────────────────┐
11:43:34 PM: │ Plugin "netlify-plugin-form-submissions" internal error │
11:43:34 PM: └─────────────────────────────────────────────────────────┘
11:43:34 PM: ​
11:43:34 PM:   Error message
11:43:34 PM:   FetchError: invalid json response body at https://api.netlify.com/api/v1/sites/fe7d005d-5f41-4fd1-8a4c-93390f4eb8cf/forms?access_token=**** reason: Unexpected end of JSON input
11:43:34 PM: ​
11:43:34 PM:   Plugin details
11:43:34 PM:   Package:        netlify-plugin-form-submissions
11:43:34 PM:   Version:        0.1.3
11:43:34 PM:   Repository:     git+https://github.com/philhawksworth/netlify-plugin-form-submissions.git
11:43:34 PM:   npm link:       https://www.npmjs.com/package/netlify-plugin-form-submissions
11:43:34 PM:   Report issues:  https://github.com/philhawksworth/netlify-plugin-form-submissions/issues
11:43:34 PM: ​
11:43:34 PM:   Error location
11:43:34 PM:   In "onPreBuild" event in "netlify-plugin-form-submissions" from netlify.toml and package.json
11:43:34 PM:       at /opt/build/repo/node_modules/node-fetch/lib/index.js:272:32
11:43:34 PM:       at processTicksAndRejections (internal/process/task_queues.js:97:5)
11:43:34 PM:       at async onPreBuild (/opt/build/repo/node_modules/netlify-plugin-form-submissions/index.js:34:19)
11:43:34 PM:       at async Object.run (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/run.js:13:3)
11:43:34 PM:       at async handleEvent (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/child/main.js:34:38)
11:43:34 PM:       at async process.<anonymous> (/opt/buildhome/.netlify-build-nvm/versions/node/v12.16.3/lib/node_modules/@netlify/build/src/plugins/ipc.js:102:9)
11:43:34 PM: ​
11:43:34 PM:   Error properties
11:43:34 PM:   { type: 'invalid-json' }
11:43:34 PM: ​
11:43:34 PM:   Resolved config
11:43:34 PM:   build:
11:43:34 PM:     command: npm run build
11:43:34 PM:     commandOrigin: config
11:43:34 PM:     environment:
11:43:34 PM:       - API_AUTH
11:43:34 PM:       - NETLIFY_AUTH_TOKEN
11:43:34 PM:       - SLACK_WEBHOOK_URL
11:43:34 PM:       - NODE_VERSION
11:43:34 PM:     functions: /opt/build/repo/src/functions
11:43:34 PM:     publish: /opt/build/repo/dist
11:43:34 PM:   plugins:
11:43:34 PM:     - inputs: {}
11:43:34 PM:       origin: config
11:43:34 PM:       package: netlify-plugin-form-submissions
11:43:34 PM: Caching artifacts
11:43:34 PM: Started saving node modules
11:43:34 PM: Finished saving node modules
11:43:34 PM: Started saving build plugins
11:43:34 PM: Finished saving build plugins
11:43:34 PM: Started saving pip cache
11:43:35 PM: Finished saving pip cache
11:43:35 PM: Started saving emacs cask dependencies
11:43:35 PM: Finished saving emacs cask dependencies
11:43:35 PM: Started saving maven dependencies
11:43:35 PM: Finished saving maven dependencies
11:43:35 PM: Started saving boot dependencies
11:43:35 PM: Finished saving boot dependencies
11:43:35 PM: Started saving go dependencies
11:43:35 PM: Finished saving go dependencies
11:43:37 PM: Error running command: Build script returned non-zero exit code: 1
11:43:37 PM: Failing build: Failed to build site
11:43:37 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1
11:43:37 PM: Finished processing build request in 28.10087568s

Should the error message include the API error response, instead of only reporting that it was not JSON?

ehmicky commented 4 years ago

Thanks @philhawksworth!