nexmo-community / build-a-thing-video

A project being built live every two weeks at twitch.tv/vonagedevs
MIT License
3 stars 9 forks source link

Fix exception handling #20

Closed shinnlok closed 3 years ago

shinnlok commented 4 years ago

If bug fixes or new features

Found your repo via hacktoberfest and while poking around I wasn't sure why the setup wasn't working. After digging around, I realized that I put in the wrong VIDEO_KEY and VIDEO_SECRET (same as https://github.com/opentok/opentok-node/issues/208).

This exception wasn't helpful:

/usr/local/lib/node_modules/netlify-cli/node_modules/netlify-redirector/lib/redirects.js:116
      throw ex;
      ^

TypeError: Cannot read property 'sessionId' of undefined
    at OT.createSession (/home/shinn/git/build-a-thing-video/functions/session.js:37:27)
    at createSessionCallback (/home/shinn/git/build-a-thing-video/node_modules/opentok/lib/opentok.js:1129:7)
    at Request._callback (/home/shinn/git/build-a-thing-video/node_modules/opentok/lib/client.js:64:14)
    at Request.self.callback (/home/shinn/git/build-a-thing-video/node_modules/request/request.js:185:22)
    at Request.emit (events.js:198:13)
    at Request.<anonymous> (/home/shinn/git/build-a-thing-video/node_modules/request/request.js:1154:10)
    at Request.emit (events.js:198:13)
    at IncomingMessage.<anonymous> (/home/shinn/git/build-a-thing-video/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (events.js:286:20)
    at IncomingMessage.emit (events.js:203:15)

Properly handle and not swallow the exception:

Error: Failed to createSession. Error: An authentication error occurred: (403) {"code":-1,"message":"Invalid signature","description":"Invalid signature"}
Response with status 500 in 479 ms.
netlify[bot] commented 4 years ago

Deploy request for build-a-thing-video pending review.

Review with commit bec2e394ad8939cafb92219e1eee5d7253e2665b

https://app.netlify.com/sites/build-a-thing-video/deploys

phazonoverload commented 4 years ago

Does this change actually alter behaviour? My understanding is that if there's an error it will reject and the following line does not run.

I may be mistaken though.

shinnlok commented 4 years ago

@phazonoverload Promise reject does not throw an exception. If the value isn't return, then the value is ignored and the rest of the control flow continues.

phazonoverload commented 4 years ago

Today I learnt. Thanks for that! I review PRs live on my show Build a Thing - next is a week today at 6PM UK time.