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.5K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 8 Federated
- 2.9K Transform
- 100 SQL DataFlows
- 616 Datasets
- 2.2K Magic ETL
- 3.8K Visualize
- 2.5K Charting
- 731 Beast Mode
- 55 App Studio
- 40 Variables
- 682 Automate
- 175 Apps
- 451 APIs & Domo Developer
- 46 Workflows
- 10 DomoAI
- 35 Predict
- 14 Jupyter Workspaces
- 21 R & Python Tiles
- 394 Distribute
- 113 Domo Everywhere
- 275 Scheduled Reports
- 6 Software Integrations
- 122 Manage
- 119 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 10 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 107 Community Announcements
- 4.8K Archive