diff --git a/cloudflare/fetchevent.go b/cloudflare/fetchevent.go index 9fa64ce..a4ff375 100644 --- a/cloudflare/fetchevent.go +++ b/cloudflare/fetchevent.go @@ -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") +}