scalajs getCause on Ajax.post onFailure

时间:2018-08-02 15:52:57

标签: ajax post error-handling scala.js

尝试获取Ajax.post失败的原因(使用Scala.Js),但仅获取类名:

Ajax.post(
  url = "...",
  data = "...",
  headers = Map("Content-Type"->"application/json; charset=utf-8",
                "Csrf-Token" -> "...")
).map(_.responseText).map(
  content => content match {
    case _                  => ...
  }
).onFailure {
  case err => log.info(s"failure ${err.toString} ${err.getCause} ${err.getMessage}")
}

我得到:

failure org.scalajs.dom.ext.AjaxException null null

是否可以找到原因? 谢谢

1 个答案:

答案 0 :(得分:0)

我不这么认为。由于AjaxException的原因无法构建:

case class AjaxException(xhr: dom.XMLHttpRequest) extends Exception {
  def isTimeout = xhr.status == 0 && xhr.readyState == 4
}