Domo Connector trap errors
I have created a connector which works fine in Dev and has no problems when creating a dataset from Dev - however when I publish it I get error
'An error occurred during processing: Domo is ready, but the script has errors: "SyntaxError: Unexpected token < in JSON at position 0"; at line number 7; '
There is no problem with the code but apparently there is something in the returned data which DOMO Dev has no problem with however DOMO Prod cannot handle.
It seems to occur when I try to start Parsing the data "var jsonRes = JSON.parse(res);".
I there a good way to catch this error?
I'm pulling the data in pages of 10 so this section is:
for(i=0;i<1000;++i) {
var res = httprequest.get(baseUrl + "?cursor=" + Cursor);
var jsonRes = JSON.parse(res);
allData = allData.concat(jsonRes.data);
Cursor = jsonRes.pagination.nextCursor;
if(Cursor == null) {
break;
}
}
Best Answer
-
The seems to be pointing to an invalid JSON response. It indicates the response might be HTML…such as when an API call returns an error message. You could try to capture what is happening by adding some error handling code.
for (var i = 0; i < 1000; ++i) {
var res = httprequest.get(baseUrl + "?cursor=" + Cursor);
try {
// Check if the response is valid JSON
var jsonRes = JSON.parse(res);
// If parsing was successful, process the data
allData = allData.concat(jsonRes.data);
Cursor = jsonRes.pagination.nextCursor;
// Break the loop if there is no next cursor
if (Cursor == null) {
break;
}
} catch (e) {
// Log the error and response for debugging
console.log("Error parsing JSON at iteration " + i + ": " + e.message);
console.log("Response: " + res);
// Handle different scenarios depending on what the response contains
if (res.includes("<html>")) {
console.log("Received HTML instead of JSON. Possible server error or wrong endpoint.");
} else {
console.log("Unexpected response format.");
}
// Optionally, you can choose to break or continue based on the error
break; // Stop execution or continue to the next iteration
}
}** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **0
Answers
-
The seems to be pointing to an invalid JSON response. It indicates the response might be HTML…such as when an API call returns an error message. You could try to capture what is happening by adding some error handling code.
for (var i = 0; i < 1000; ++i) {
var res = httprequest.get(baseUrl + "?cursor=" + Cursor);
try {
// Check if the response is valid JSON
var jsonRes = JSON.parse(res);
// If parsing was successful, process the data
allData = allData.concat(jsonRes.data);
Cursor = jsonRes.pagination.nextCursor;
// Break the loop if there is no next cursor
if (Cursor == null) {
break;
}
} catch (e) {
// Log the error and response for debugging
console.log("Error parsing JSON at iteration " + i + ": " + e.message);
console.log("Response: " + res);
// Handle different scenarios depending on what the response contains
if (res.includes("<html>")) {
console.log("Received HTML instead of JSON. Possible server error or wrong endpoint.");
} else {
console.log("Unexpected response format.");
}
// Optionally, you can choose to break or continue based on the error
break; // Stop execution or continue to the next iteration
}
}** Was this post helpful? Click Agree or Like below. **
** Did this solve your problem? Accept it as a solution! **0 -
Thanks :)
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 753 Beast Mode
- 61 App Studio
- 41 Variables
- 692 Automate
- 177 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive