Skip to content

Commit 34b3267

Browse files
committed
preview server: improve reliance to connection errors
1 parent 3628627 commit 34b3267

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

src/command/preview/preview.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,16 @@ export async function preview(
196196
// serve project
197197
for await (const conn of listener) {
198198
(async () => {
199-
for await (const { request, respondWith } of Deno.serveHttp(conn)) {
200-
try {
199+
try {
200+
for await (const { request, respondWith } of Deno.serveHttp(conn)) {
201201
await respondWith(handler(request));
202-
} catch (err) {
203-
warning(err.message);
202+
}
203+
} catch (err) {
204+
warning(err.message);
205+
try {
206+
conn.close();
207+
} catch {
208+
//
204209
}
205210
}
206211
})();

src/project/serve/serve.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,20 @@ export async function serveProject(
534534

535535
// serve project
536536
const handler = httpFileRequestHandler(handlerOptions);
537+
538+
// serve project
537539
for await (const conn of listener) {
538540
(async () => {
539-
for await (const { request, respondWith } of Deno.serveHttp(conn)) {
540-
try {
541+
try {
542+
for await (const { request, respondWith } of Deno.serveHttp(conn)) {
541543
await respondWith(handler(request));
542-
} catch (err) {
543-
warning(err.message);
544+
}
545+
} catch (err) {
546+
warning(err.message);
547+
try {
548+
conn.close();
549+
} catch {
550+
//
544551
}
545552
}
546553
})();

0 commit comments

Comments
 (0)