Skip to content

Commit 5bdda40

Browse files
authored
Merge pull request #1755 from Matsuuu/openapi-ts-watch-no-head
2 parents f14b57b + 82f7c14 commit 5bdda40

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

.changeset/selfish-nails-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
fix: Wrap the GET request in watch mode with try-catch to prevent crashes on no-head watch targets

packages/openapi-ts/src/getSpec.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,21 @@ export const getSpec = async ({
109109
}
110110
}
111111

112-
const fileRequest = await sendRequest({
113-
init: {
114-
method: 'GET',
115-
},
116-
timeout,
117-
url: resolvedInput.path,
118-
});
119-
response = fileRequest.response;
112+
try {
113+
const fileRequest = await sendRequest({
114+
init: {
115+
method: 'GET',
116+
},
117+
timeout,
118+
url: resolvedInput.path,
119+
});
120+
response = fileRequest.response;
121+
} catch (ex) {
122+
return {
123+
error: 'not-ok',
124+
response: new Response(ex.message),
125+
};
126+
}
120127

121128
if (!response.ok) {
122129
// assume the server is no longer running

0 commit comments

Comments
 (0)