Skip to content

Commit

Permalink
Guard access of response.type to support Cloudflare Workers (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeylemmon authored Jun 3, 2022
1 parent 80de3ee commit 2addcf2
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/twirp-transport/src/twirp-transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ export class TwirpFetchTransport implements RpcTransport {

defHeader.resolve(parseMetadataFromResponseHeaders(fetchResponse.headers));

switch (fetchResponse.type) {
// Cloudflare Workers throw when the type property of a fetch response
// is accessed, so wrap access with try/catch. See:
// * https://developers.cloudflare.com/workers/runtime-apis/response/#properties
// * https://github.com/cloudflare/miniflare/blob/72f046e/packages/core/src/standards/http.ts#L646
let responseType
try { responseType = fetchResponse.type } catch {}
switch (responseType) {
case "error":
case "opaque":
case "opaqueredirect":
Expand Down

0 comments on commit 2addcf2

Please sign in to comment.