Capturing the external Oracle DB error from a SQL Query service call
Greetings!
I have an API endpoint that fetches data from an external Oracle database that I have developed in Thingworx. Naturally, it utilizes the Database Thing, on which are 2 services: a Local (JavaScript) service for the endpoint's business logic, and a SQL (Query) service that executes the query against the external database using SQL that gets defined in the JavaScript service based upon the values of the input parameters that are passed. For example, the endpoint can be called to fetch user information by passing EITHER an ID number or an Email address, and the SQL is adjusted accordingly before the SQL(Query) service is called to execute it.
Overall, the endpoint works well. The challenge I am facing is that I want to trap for specific Oracle DB errors, and since I'm passing my SQL query off from the TWX Local (JavaScript) service to the TWX SQL (Query) service, I "lose" the Oracle error object and instead get a generic JavaScript error.
To be more specific, I use the following try/catch code in the JavaScript service and then call the SQL(Query) service to execute my SELECT statement:
var dbResults = {};
try {
dbResults = me.RunDatabaseQuery( {query:dbQuery} );
} catch( queryError ) {
logger.debug("database-controller.get-user.executeDBQuery(dbQuery): DB Query Error: " +
"'queryError.name' = '" + queryError.name + "': " +
"'queryError.message' = \"" + queryError.message + "\" " );
}
return( dbResults );
If the external database is offline or my Schema doesn't have access, Oracle throws a "table or view does not exist" error. That's the information I want returned to the API caller as part of the result set.
But my service only gets a generic JavaScript error saying the query failed, as shown in my debug log:
database-controller.get-user.executeDBQuery(dbQuery): DB Query Error: 'queryError.name' = 'JavaException': 'queryError.message' = "java.lang.Exception: Execute Query failed. Please check Database logs for more details."
However, the TWX DatabaseLog.log does show the Oracle error info I want, so I know TWX has the info somewhere:
"Unable to Invoke Service RunDatabaseQuery on database-controller : Execute Query failed. java.sql.SQLSyntaxErrorException: ORA-00942: table or view does not exist_"
How can I get that Oracle exception info back to my JavaScript service when I call the "RunDatabaseQuery" SQL (Query) service?...other than having to parse the databaselog file in real time, which seems rather absurd?

