kopia lustrzana https://github.com/c9/core
Merge pull request +11473 from c9/require-cache-error
improve error handlidng of cached requiresmf-sdk
commit
0b52a17e78
|
@ -443,9 +443,15 @@ var loadCached = function(path, cb) {
|
|||
return loadText(path, cb);
|
||||
function loadNew() {
|
||||
loadText(path, function(e, val, xhr) {
|
||||
var m = cb(e, val);
|
||||
if (val) {
|
||||
try {
|
||||
var m = cb(e, val);
|
||||
} catch(err) {
|
||||
ideCache.delete(path);
|
||||
e = err;
|
||||
}
|
||||
if (!e) {
|
||||
var ETAG = xhr.getResponseHeader("ETAG");
|
||||
if (!ETAG) return;
|
||||
var res = new Response(val);
|
||||
res.headers.set("ETAG", ETAG);
|
||||
var req = new Request(path);
|
||||
|
@ -467,13 +473,16 @@ var loadCached = function(path, cb) {
|
|||
ideCache.match(path).then(function(e) {
|
||||
if (!e)
|
||||
return loadNew();
|
||||
e.text().then(function(val) {
|
||||
return e.text().then(function(val) {
|
||||
var deps = e.headers.get("deps");
|
||||
if (typeof deps == "string")
|
||||
deps = deps ? deps.split(",") : [];
|
||||
|
||||
cb(null, val, deps);
|
||||
});
|
||||
}).catch(function() {
|
||||
loadNew();
|
||||
ideCache.delete(path);
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -532,9 +541,15 @@ function post(path, val, progress, cb) {
|
|||
var xhr = new window.XMLHttpRequest();
|
||||
xhr.open("POST", path, true);
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
xhr.onload = function(e) { cb(null, xhr.responseText, xhr); };
|
||||
xhr.onload = function(e) {
|
||||
if (xhr.status > 399 && xhr.status < 600)
|
||||
return cb(xhr);
|
||||
cb(null, xhr.responseText, xhr);
|
||||
};
|
||||
xhr.onreadystatechange = function(e) { progress(xhr.responseText, xhr); };
|
||||
xhr.onabort = xhr.onerror = function(e) { cb(e); };
|
||||
xhr.onabort = xhr.onerror = function(e) {
|
||||
xhr && cb(e);
|
||||
};
|
||||
xhr.send(val);
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue