Fix for promise handler in oauth middleware.

Merged
#9 · Created  · Last updated

Merged pull request

Merged in sday_atlassian/atlassian-connect-express/oauth-promise-wtf (pull request #9)

5b9e50e·Author: ·Closed by: ·2013-10-16

Description

This fixes an issue in the oauth middleware that causes requests to hang indefinitely. I'll do my best to explain this one clearly ;)

Consider the following code snippet:

var RSVP = require('rsvp'); var promise = new RSVP.Promise(function(resolve,reject) { setTimeout(resolve, 1000); }); promise.then(function() { throw new Error(":("); }, function() { console.log("This won't be called."); }); promise.then(function() { throw new Error(":("); }).fail(function() { console.log("But this will."); });

The problem here is that if a promise handler itself throws an error (NOT to be confused with the promise itself being rejected due to an error), the fail callback is not called if it's passed as the second argument to a single then(). Instead, you must chain a fail() after the original promise handler. If this doesn't make sense, let me know and I'll try explaining it a different way :)

Anyway, the issue I was having is that lib/internal/oauth.js itself is exploding (for reasons unknown, that may result in a separate PR once I nail that issue) in the exported verify() function. This causes the promise handler to throw an error, and the fail handler never gets called. Instead, the error is swallowed silently, the response isn't cleaned up nor is next() called. Yay async programming!

I didn't go hunting for this promise handler issue elsewhere in the code.

0 attachments

0 comments

Loading commits...