Skip to content

Commit ed0e801

Browse files
committed
chore: improve Promise detection
1 parent c18d41e commit ed0e801

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

package-lock.json

+6-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
"directories": {
5050
"test": "test"
5151
},
52-
"dependencies": {},
52+
"dependencies": {
53+
"is-promise": "^2.2.2"
54+
},
5355
"devDependencies": {
5456
"@commitlint/cli": "^11.0.0",
5557
"@commitlint/config-conventional": "^11.0.0",

src/lib/builder_functions.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const isPromise = require('is-promise')
2+
13
const { HTTP_STATUS_METHOD_NOT_ALLOWED, HTTP_STATUS_OK } = require('./consts')
24

35
const augmentResponse = (response) => {
@@ -24,7 +26,7 @@ const wrapHandler = (handler) => (event, context, callback) => {
2426
const wrappedCallback = (error, response) => callback(error, augmentResponse(response))
2527
const execution = handler(event, context, wrappedCallback)
2628

27-
if (execution instanceof Promise) {
29+
if (isPromise(execution)) {
2830
// eslint-disable-next-line promise/prefer-await-to-then
2931
return execution.then(augmentResponse)
3032
}

0 commit comments

Comments
 (0)