bullhorn / taurus

Typescript client for the Bullhorn REST API
MIT License
10 stars 6 forks source link

UnhandledPromiseRejectionWarning Error #17

Closed martinmicunda closed 5 years ago

martinmicunda commented 6 years ago

Hi @bvkimball

It seems like Taurus doesn't work with promises correctly:

Issue 1: If I try to query for none existing candidate I would expect to handle the error in my subscription, however, the Taurus is throwing the error and it doesn't pass the error to subscription.

let record: Entity<Candidate> = new Entity(EntityTypes.Candidate).fields('id', 'name');
// use none existing canditate id
record.get(100);
record.subscribe((response) => {
    console.log(record.data);
}, (error) => console.error('should print the error', error));

Error message:

(node:31240) UnhandledPromiseRejectionWarning: Error: Request failed with status code 404
    at createError (/Users/martinmicunda/projects/bigbang/aviation-api.cae.com/node_modules/@bullhorn/taurus/node_modules/axios/lib/core/createError.js:16:15)
    at settle (/Users/martinmicunda/projects/bigbang/aviation-api.cae.com/node_modules/@bullhorn/taurus/node_modules/axios/lib/core/settle.js:18:12)
    at IncomingMessage.handleStreamEnd (/Users/martinmicunda/projects/bigbang/aviation-api.cae.com/node_modules/@bullhorn/taurus/node_modules/axios/lib/adapters/http.js:192:11)
    at emitNone (events.js:111:20)
    at IncomingMessage.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1064:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)
(node:31240) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 4)
(node:31240) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Issue 2: In my application I prefer to use Promises and not observables and as the observable has toPromise() the below code should work, however it seems like promise is lost somewehere as console.log or console.error are not executed.

let record: Entity<Candidate> = new Entity(EntityTypes.Candidate).fields('id', 'name');
record.get(100);
try {
  await record.toPromise();
  console.log('print me');
} catch (error) {
   console.error('print error', error);
}
amrutha-rajiv commented 5 years ago

:tada: This issue has been resolved in version 2.1.6 :tada:

The release is available on:

Your semantic-release bot :package::rocket: