Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

"Error: Cannot parse JSON response" server is returning HTML, not JSON #325

@buzzware

Description

@buzzware

Some very simple code trying to use this client fails as follows :

const {BigQuery} = require("@google-cloud/bigquery");

const BigQueryClient = class {

	constructor(aDatasetName) {
		this.datasetname = aDatasetName;
		this.bigquery = new BigQuery();
		this.dataset = this.bigquery.dataset(this.datasetname);
	}

	static new(...args) {
		return new BigQueryClient(...args);
	}

	async ensureTable(aName) {
		await this.dataset.exists();
		let table = this.dataset.table(aName);
		try {
			await table.exists();
		} catch(e) {
			await table.create();
		}
	}

	async upsert(aCollection,aId,aData) {
		let table = this.dataset.table(aCollection);
		let packet = {
			insertId: aId,
			json: aData
		};
		try {
			await table.insert(packet);
		} catch (e) {	// if already exists
			await table.update(packet);
		}
	}

};

const BigQueryClient = require('../BigQueryClient');

describe('BigQuery test', function() {

	let bigQuery;

	beforeEach(async function () {
		this.timeout(30000);
		bigQuery = new BigQueryClient();
	});

	it('ensureTable', async function () {
		this.timeout(30000);
		await bigQuery.ensureTable('Things');
		console.log('done');
	});

});

table.exists() fails like this, because the server returns a string "Not Found" instead of JSON.

Error: Cannot parse JSON response
    at Util.parseHttpRespBody (functions/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/build/src/util.js:167:42)
    at Util.handleResp (functions/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/build/src/util.js:116:117)
    at retryRequest (functions/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/build/src/util.js:403:22)
    at onResponse (functions/node_modules/retry-request/index.js:200:7)
    at /Users/gary/repos/2018/connect2bet/functions/node_modules/teeny-request/build/src/index.js:222:13
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

image

table.create() also fails similarly

Error: Cannot parse JSON response
    at Util.parseHttpRespBody (functions/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/build/src/util.js:167:42)
    at Util.handleResp (functions/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/build/src/util.js:116:117)
    at retryRequest (functions/node_modules/@google-cloud/bigquery/node_modules/@google-cloud/common/build/src/util.js:403:22)
    at onResponse (functions/node_modules/retry-request/index.js:200:7)
    at /Users/gary/repos/2018/connect2bet/functions/node_modules/teeny-request/build/src/index.js:222:13
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)

because the server returns HTML :

<!DOCTYPE html>
<html lang=en>
  <meta charset=utf-8>
  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">
  <title>Error 404 (Not Found)!!1</title>
  <style>
    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}
  </style>
  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>
  <p><b>404.</b> <ins>That’s an error.</ins>
  <p>The requested URL <code>/bigquery/v2/projects/connect2bet-test2/datasets/tables</code> was not found on this server.  <ins>That’s all we know.</ins>

Environment details

  • OS: OSX
  • Node.js version: 8
  • npm version:
  • @google-cloud/bigquery version: 2.0.6 & 2.0.3

Steps to reproduce

  1. ?
  2. ?

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

Metadata

Metadata

Assignees

Labels

🚨This issue needs some love.api: bigqueryIssues related to the googleapis/nodejs-bigquery API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions