This is question -- not an issue
I'm trying to implement simple try/catch functionality with async/await.
In my case I'm using TypeScript 2.x compiling to ES6.
I have a function like this:
public async getTestDatas(id: string): Promise<Array<ITestData>> {
const retVal: Array<ITestData> = [];
const datastore = await GCPUtils.getDatastore();
const query = datastore.createQuery(DBConstant.TestDataKind)
.filter('id', '=', id);
try {
const results: any[] = await datastore.runQuery(query);
if (results.length > 0) {
const entries: any[] = results[0];
entries.forEach(testData => {
retVal.push(testData as ITestData);
});
}
} catch (err) {
console.log(err);
}
return retVal;
}
What I'm expecting is if there is an issue with the query -- it will land on the catch (err) { console.log(err); }
When I experience an exceptions - they generally just fail
-when debugging - it will just except out down in the datastore api code (and it's very difficult to figure out why)
-at runtime -- the process (express app) spits a ' we caught an unhandled exception and we're not going to do that forever!!!' warning
edit: I should mention most of the time these turn out to be malformed / empty keys
I'm assuming my expectations are incorrect -- but is there a way to get this working while keeping the nice try/catch syntax?
Thanks - Chad
Hey @chadbr, thanks for asking. I think you might get a better response from a wider range of experts on StackOverflow using our tags: https://stackoverflow.com/questions/tagged/google-cloud-platform+nodejs (Maybe add on TypeScript as well).
If you do post, please link back here. I'll close this issue, but if anyone else who sees this knows the answer, of course feel free to help out :)
ok, fwiw, no responses...