【问题标题】:scalajs getCause on Ajax.post onFailurescalajs getCause on Ajax.post onFailure
【发布时间】:2019-01-10 11:14:06
【问题描述】:

尝试获取 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

是否有可能找到原因? 谢谢

【问题讨论】:

    标签: ajax post error-handling scala.js


    【解决方案1】:

    我不这么认为。由于AjaxException 不能用原因构造:

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

    【讨论】:

    • 谢谢,看来我必须检查 Ajax 服务器状态和就绪状态以了解更多详细信息。
    猜你喜欢
    • 2022-01-19
    • 2020-01-06
    • 2016-01-12
    • 2013-01-11
    • 2015-06-30
    • 2020-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多