Skip to content

Commit f89bd76

Browse files
committed
fix: Wrap the GET request in watch mode with try-catch to prevent crashes on no-head watch targets
1 parent f14b57b commit f89bd76

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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)