【发布时间】:2011-11-30 16:25:37
【问题描述】:
所以,我一直在阅读 this article 关于 LiftWeb 中 Box 的使用,这似乎是官方文档的一部分,因为它通过源代码 cmets 链接。 我的问题是,为什么 Box/Failure 比在没有 null 的情况下实际编码并抛出异常会更可取,该异常将在顶层捕获并转换为适当的错误代码/消息。所以不是
case "user" :: "info" :: _ XmlGet _ =>
for {
id <- S.param("id") ?~ "id param missing" ~> 401
u <- User.find(id) ?~ "User not found"
} yield u.toXml
为什么不
case "user" :: "info" :: _ XmlGet _ => User.find(S.param("id").openOrThrow(
new IllegalArgumentException("idParamMissing"))).toXml
并让User.find 抛出类似NotFoundException 的东西
【问题讨论】:
-
好问题。我从来没想过……
-
@drozzy 确保您还阅读了邮件列表中的答案:goo.gl/5Lv7V