Skip to content

Commit b0928ac

Browse files
authored
feat: improve error handling within startCallback and endCallback (#3969)
1 parent 74deac7 commit b0928ac

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

lib/Server.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -2175,7 +2175,9 @@ class Server {
21752175
}
21762176

21772177
startCallback(callback) {
2178-
this.start().then(() => callback(null), callback);
2178+
this.start()
2179+
.then(() => callback(null), callback)
2180+
.catch(callback);
21792181
}
21802182

21812183
async stop() {
@@ -2235,7 +2237,9 @@ class Server {
22352237
}
22362238

22372239
stopCallback(callback) {
2238-
this.stop().then(() => callback(null), callback);
2240+
this.stop()
2241+
.then(() => callback(null), callback)
2242+
.catch(callback);
22392243
}
22402244

22412245
// TODO remove in the next major release

test/e2e/api.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,29 @@ describe("API", () => {
8080
});
8181
});
8282

83+
it(`should catch errors within startCallback`, async () => {
84+
const compiler = webpack(config);
85+
const server = new Server(
86+
{ port, static: "https://absolute-url.com/somewhere" },
87+
compiler
88+
);
89+
90+
await new Promise((resolve) => {
91+
server.startCallback((err) => {
92+
expect(err.message).toEqual(
93+
"Using a URL as static.directory is not supported"
94+
);
95+
resolve();
96+
});
97+
});
98+
99+
await new Promise((resolve) => {
100+
server.stopCallback(() => {
101+
resolve();
102+
});
103+
});
104+
});
105+
83106
it(`should work when using configured manually`, async () => {
84107
const compiler = webpack({
85108
...config,

0 commit comments

Comments
 (0)