Skip to content

Commit 76f1c2f

Browse files
committed
Improve HMR error handling webpack#410
1 parent e4dc029 commit 76f1c2f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/JsonpMainTemplatePlugin.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,20 +157,30 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
157157
return callback(new Error("No browser support"));
158158
try {
159159
var request = new XMLHttpRequest();
160-
request.open("GET", $require$.p + $hotMainFilename$, true);
160+
var requestPath = $require$.p + $hotMainFilename$;
161+
request.open("GET", requestPath, true);
162+
request.timeout = 10000;
161163
request.send(null);
162164
} catch(err) {
163165
return callback(err);
164166
}
165167
request.onreadystatechange = function() {
166168
if(request.readyState !== 4) return;
167-
if(request.status !== 200 && request.status !== 304) {
169+
if(request.status === 0) {
170+
// timeout
171+
callback(new Error("Manifest request to " + requestPath + " timed out."));
172+
} else if(request.status === 404) {
173+
// no update available
168174
callback();
175+
} else if(request.status !== 200 && request.status !== 304) {
176+
// other failure
177+
callback(new Error("Manifest request to " + requestPath + " failed."));
169178
} else {
179+
// success
170180
try {
171181
var update = JSON.parse(request.responseText);
172182
} catch(e) {
173-
callback();
183+
callback(e);
174184
return;
175185
}
176186
callback(null, update);

0 commit comments

Comments
 (0)