From 16509edf41fcc27a5e16490b9dd854ca0d93a17e Mon Sep 17 00:00:00 2001 From: Sean McBride Date: Mon, 20 Mar 2023 11:44:13 -0700 Subject: [PATCH] Throw non-JSON responses as errors --- generator/template.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/generator/template.go b/generator/template.go index 6c8070e..f734214 100644 --- a/generator/template.go +++ b/generator/template.go @@ -216,10 +216,15 @@ export function fetchReq(path: string, init?: InitReq): Promise { const url = pathPrefix ? ` + "`${pathPrefix}${path}`" + ` : path - return fetch(url, req).then(r => r.json().then((body: O) => { - if (!r.ok) { throw body; } - return body; - })) as Promise + return fetch(url, req).then((r) => + r + .json() + .catch((err) => { throw r; }) + .then((body: O) => { + if (!r.ok) { throw body; } + return body; + }), + ) as Promise; } // NotifyStreamEntityArrival is a callback that will be called on streaming entity arrival