Skip to content

Commit

Permalink
Allow SDK errors to be thrown out of final request callback.
Browse files Browse the repository at this point in the history
Fixes #392, referencing #74.
  • Loading branch information
lsegal committed Oct 22, 2014
1 parent 1478892 commit 1e277ec
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 24 deletions.
23 changes: 9 additions & 14 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,19 @@ function isTerminalState(machine) {

var fsm = new AcceptorStateMachine();
fsm.setupStates = function() {
var transition = function(err, done) {
var transition = function(_, done) {
var self = this;

try {
var self = this;
self.emit(self._asm.currentState, function() {
var nextError = self.response.error;
if (nextError && nextError !== err && isTerminalState(self)) {
throw nextError;
}

done(nextError);
done(self.response.error);
});

} catch (e) {
if (e !== err && isTerminalState(self)) {
AWS.SequentialExecutor.prototype.unhandledErrorCallback.call(this, e);
done();
} catch (err) {
if (isTerminalState(self)) {
AWS.SequentialExecutor.prototype.unhandledErrorCallback.call(self, err);
} else {
done(e);
self.response.error = err;
done(err);
}
}
};
Expand Down
7 changes: 1 addition & 6 deletions lib/sequential_executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,7 @@ AWS.SequentialExecutor = AWS.util.inherit({
listener.apply(self, args.concat([callNextListener]));
return; // stop here, callNextListener will continue
} else { // synchronous listener
try {
listener.apply(self, args);
} catch (err) {
doneCallback.call(self, err);
return;
}
listener.apply(self, args);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/event_listeners.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,9 @@ describe 'AWS.EventListeners', ->
describe 'terminal callback error handling', ->
describe 'without domains', ->
it 'emits uncaughtException', ->
helpers.mockHttpResponse 200, {}, []
helpers.mockResponse data: {}
expect(-> (makeRequest -> invalidCode)).to.throw()
expect(completeHandler.calls.length).not.to.equal(0)
expect(completeHandler.calls.length).to.equal(1)
expect(errorHandler.calls.length).to.equal(0)
expect(retryHandler.calls.length).to.equal(0)

Expand Down
4 changes: 2 additions & 2 deletions test/helpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ MockService = AWS.Service.defineService 'mockService',
@config.region = 'mock-region'
setupRequestListeners: (request) ->
request.on 'extractData', (resp) ->
resp.data = resp.httpResponse.body.toString()
resp.data = (resp.httpResponse.body||'').toString()
request.on 'extractError', (resp) ->
resp.error =
code: resp.httpResponse.body.toString() || resp.httpResponse.statusCode
code: (resp.httpResponse.body||'').toString() || resp.httpResponse.statusCode
message: null
api: new AWS.Model.Api metadata:
endpointPrefix: 'mockservice'
Expand Down

0 comments on commit 1e277ec

Please sign in to comment.