2015-12-09 25 views
0

這一個是混亂來形容後,所以我只是把視頻mithril.js死亡m.request收到一個錯誤

https://dl.dropboxusercontent.com/s/ju485susn7ypsgx/2015-12-09_15-03-50.mp4?dl=0

當我關閉服務器電源,m.request拋出錯誤(顯然)net::ERR_CONNECTION_REFUSED

  1. 我該如何處理這些錯誤,只是把數據放入一個空數組[](我知道.then接受成功和失敗的回調,但它似乎不工作)
  2. 爲什麼重新啓動服務器後應用程序不能啓動? (看起來問題是m.route停止工作?)
+0

我認爲可能發生的是該錯誤阻止了m.redraw的執行。米索里爾的m.request承諾不包括一個捕獲 - 你可以使用一個更好的ajax庫,有一個捕獲(我愛mithril但m.request是一團糟),或包裝你的m.request在承諾和捕獲任何錯誤。然後你可以用一個空數組解決並手動調用m.redraw(我不知道這是否有必要)。 – dcochran

+0

@dcochran我在這裏發現了具體的問題:http://i.imgur.com/HaXEKBO.png 'deserialize'是'JSON.parse',它實際上在一個'try'塊中......怎麼可能這個錯誤沒有被捕獲!? http://i.imgur.com/kZ74Arv.png –

回答

1

我通過編輯mithril.js源碼修復了這個問題。我必須將電話打到m.endComputation底部的finally區塊。

我不明白爲什麼try/catch不起作用,爲什麼這finally是必需的。但我想我會把它作爲一個錯誤發佈。

xhrOptions.onload = xhrOptions.onerror = function(e) { 
     try { 
      e = e || event; 
      var unwrap = (e.type === "load" ? xhrOptions.unwrapSuccess : xhrOptions.unwrapError) || identity; 
      var response = unwrap(deserialize(extract(e.target, xhrOptions)), e.target); 
      if (e.type === "load") { 
       if (type.call(response) === ARRAY && xhrOptions.type) { 
        for (var i = 0; i < response.length; i++) response[i] = new xhrOptions.type(response[i]) 
       } 
       else if (xhrOptions.type) response = new xhrOptions.type(response) 
      } 
      deferred[e.type === "load" ? "resolve" : "reject"](response) 
     } 
     catch (e) { 
      m.deferred.onerror(e); 
      deferred.reject(e) 
     } finally { 
// This is now in a finally block 
      if (xhrOptions.background !== true) m.endComputation() 
     } 
    }; 
+1

實際上,這是預期的行爲,我曾經將它作爲一個bug提出,足夠有趣:https://github.com/lhorie/mithril.js/issues/780 像我說的,m.request是一團糟。您需要將提取選項傳入您的m.request(請參閱鏈接)。 – dcochran

+1

@dcochran Wth ?!他們很愚蠢,特別是考慮到我通過增加一個'finally'塊來修復它。我曾與一些貢獻者討論過這個問題,我想他會在解決一些雜亂的Ajax代碼的同時提出修復建議。 –