diff --git a/cloudflare/r2object.go b/cloudflare/r2object.go index c3fd027..d721240 100644 --- a/cloudflare/r2object.go +++ b/cloudflare/r2object.go @@ -82,6 +82,9 @@ type R2HTTPMetadata struct { } func toR2HTTPMetadata(v js.Value) (R2HTTPMetadata, error) { + if v.IsUndefined() || v.IsNull() { + return R2HTTPMetadata{}, nil + } cacheExpiry, err := jsutil.MaybeDate(v.Get("cacheExpiry")) if err != nil { return R2HTTPMetadata{}, fmt.Errorf("error converting cacheExpiry: %w", err) diff --git a/internal/jsutil/jsutil.go b/internal/jsutil/jsutil.go index cd14c22..1175029 100644 --- a/internal/jsutil/jsutil.go +++ b/internal/jsutil/jsutil.go @@ -66,6 +66,9 @@ func AwaitPromise(promiseVal js.Value) (js.Value, error) { // StrRecordToMap converts JavaScript side's Record into map[string]string. func StrRecordToMap(v js.Value) map[string]string { + if v.IsUndefined() || v.IsNull() { + return map[string]string{} + } entries := ObjectClass.Call("entries", v) entriesLen := entries.Get("length").Int() result := make(map[string]string, entriesLen)