Skip to content

Commit 3831ea0

Browse files
authored
fix(functions): await functions error handling (#7186)
1 parent 4f57f10 commit 3831ea0

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

src/lib/functions/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ export const createHandler = function (options: GetFunctionsServerOptions): Requ
254254
return
255255
}
256256

257-
handleSynchronousFunction({ error, functionName: func.name, result, request, response })
257+
await handleSynchronousFunction({ error, functionName: func.name, result, request, response })
258258
}
259259
}
260260
}

src/lib/functions/synchronous.ts

+6-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const addHeaders = (headers: undefined | Record<string, string | string[]>, resp
2525
})
2626
}
2727

28-
export const handleSynchronousFunction = function ({
28+
export const handleSynchronousFunction = async function ({
2929
error: invocationError,
3030
functionName,
3131
request,
@@ -37,7 +37,7 @@ export const handleSynchronousFunction = function ({
3737
request: express.Request
3838
response: express.Response
3939
result: null | LambdaEvent
40-
}): void {
40+
}): Promise<void> {
4141
if (invocationError) {
4242
const error = getNormalizedError(invocationError)
4343

@@ -47,26 +47,23 @@ export const handleSynchronousFunction = function ({
4747
}\n${chalk.dim(error.stackTrace.join('\n'))}`,
4848
)
4949

50-
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- XXX(serhalp): real bug, fixed in stacked PR.
51-
handleErr(invocationError, request, response)
50+
await handleErr(invocationError, request, response)
5251
return
5352
}
5453

5554
const { error } = validateLambdaResponse(result)
5655
if (error) {
5756
logPadded(`${NETLIFYDEVERR} ${error}`)
5857

59-
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- XXX(serhalp): real bug, fixed in stacked PR.
60-
handleErr(error, request, response)
58+
await handleErr(error, request, response)
6159
return
6260
}
6361

6462
// This shouldn't happen (see `InvokeFunctionResult`), but due to type lossiness TS doesn't know this here.
6563
if (result == null) {
6664
logPadded(`${NETLIFYDEVERR} Unexpected empty function response`)
6765

68-
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- XXX(serhalp): real bug, fixed in stacked PR.
69-
handleErr('Unexpected empty function response', request, response)
66+
await handleErr('Unexpected empty function response', request, response)
7067
return
7168
}
7269

@@ -87,8 +84,7 @@ export const handleSynchronousFunction = function ({
8784
}`,
8885
)
8986

90-
// eslint-disable-next-line @typescript-eslint/no-floating-promises -- XXX(serhalp): real bug, fixed in stacked PR.
91-
handleErr(wrappedHeadersError, request, response)
87+
await handleErr(wrappedHeadersError, request, response)
9288
return
9389
}
9490

0 commit comments

Comments
 (0)