Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/server/rollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,45 @@ Rollbar.errorHandler = function() {
}
};

Rollbar.prototype.azureFunctionHandler = function(handler) {
const AsyncFunction = (async () => {}).constructor;
if (handler instanceof AsyncFunction) {
return this.asyncAzureFunctionHandler(handler);
}
return this.syncAzureFunctionHandler(handler);
};

Rollbar.prototype.asyncAzureFunctionHandler = function(handler) {
const self = this;
return function(context, ...args) {
return new Promise(function(resolve, reject) {
handler(context, ...args)
.then(function(result) {
resolve(result);
})
.catch(function(error) {
self.error(error);
self.wait(function() {
reject(error);
});
});
})
}
}
Rollbar.prototype.syncAzureFunctionHandler = function(handler) {
const self = this;
return async function(context, ...args) {
try {
return handler(context, ...args);
} catch (error) {
self.error(error);
self.wait(function() {
throw error;
})
}
}
}

Rollbar.prototype.lambdaHandler = function(handler, timeoutHandler) {
if (handler.length <= 2) {
return this.asyncLambdaHandler(handler, timeoutHandler);
Expand Down