the code itself runs; could there be an obvious fix to this that i'm somehow missing?
the debugger in Webstorm highlights the reject statements during debugging, but the code never actually rejects; the debugger then highlights the fulfill statement and finally returns to the then block, however, the then block is immediately skipped in the next step and the catch block then runs
i have another promise wrapped around the then-catch code, which i'm also returning. my plan was to catch the rejection from the helper function, and after my main function catches it, reject it again as the return value (promise)
but while the debugger highlights the catch statement after getting back from the helper function, it appears that all the code inside the block is skipped over (after my helper function finishes in its entirety and gets back to the main function)
my fulfill-reject code:
public static filter(courses: Course[], filterObj: FILTER, comparison: string) { return new Promise(function (fulfill, reject) { let filter: any = (<any>filterObj)[comparison]; let names = Object.keys(filter); if (names.length !== 1) { console.log("??"); reject({"code": 400, "body": {"error": "invalid comparison"}}); } let name = names.toString(); if (!CHelpers.isDataset(name)) { reject({"code": 400, "body": {"error": "invalid comparison"}}); } let filterValue: number = filter[name]; if (typeof filterValue !== "number") { reject({"code": 400, "body": {"error": "invalid comparison"}}); } let key: string = CHelpers.getKey(name); console.log("successfully filtered " + comparison); fulfill(CHelpers.filterCourses(courses, key, filterValue, comparison)); }) } my then-catch code:
CHelpers.filter(courses, filterObj, comparison) .then(function(filteredCourses: any) { courses = filteredCourses; }) .catch(function(err: any) { return reject(err); }); my main function looks kind of like this:
doThing(input: any): Promise < {} > { return new Promise(function(fulfill, reject) { let courses: Course[]; let filterObj: FILTER = input.KEY; let comparisons: string[] = Object.keys(filterObj); let comparison: string = comparisons[0]; if (comparison === "test") { CHelpers.filter(courses, filterObj, comparison) .then(function(filteredCourses: any) { courses = filteredCourses; }) .catch(function(err: any) { return reject(err); }); } else { reject({ "code": 400, "body": { "error": "invalid body" } }); } let responseBody: {} = { render: "TABLE", result: courses }; fulfill({ "code": 200, "body": responseBody }); }); }