F: add passThroughOnException

This commit is contained in:
aki-0421 2023-04-20 07:57:04 +09:00
parent c0f7b90059
commit a9fa550371
No known key found for this signature in database
GPG Key ID: 64A8CF6D437D166A

View File

@ -12,9 +12,8 @@ import (
// It accepts an asynchronous task which the Workers runtime will execute before the handler terminates but without blocking the response.
// see: https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#waituntil
func WaitUntil(ctx context.Context, task func()) {
executionContext := cfruntimecontext.GetExecutionContext(ctx)
executionContext.Call("waitUntil", jsutil.NewPromise(js.FuncOf(func(this js.Value, pArgs []js.Value) any {
exCtx := cfruntimecontext.GetExecutionContext(ctx)
exCtx.Call("waitUntil", jsutil.NewPromise(js.FuncOf(func(this js.Value, pArgs []js.Value) any {
resolve := pArgs[0]
go func() {
task()
@ -23,3 +22,11 @@ func WaitUntil(ctx context.Context, task func()) {
return js.Undefined()
})))
}
// PassThroughOnException prevents a runtime error response when the Worker script throws an unhandled exception.
// Instead, the request forwards to the origin server as if it had not gone through the worker.
// see: https://developers.cloudflare.com/workers/runtime-apis/fetch-event/#passthroughonexception
func PassThroughOnException(ctx context.Context) {
exCtx := cfruntimecontext.GetExecutionContext(ctx)
exCtx.Call("passThroughOnException")
}