[英]Scala JSON error handling and responses
I use Scala + Lift Web Framework + MongoDB for a bunch of applications. 我将Scala + Lift Web Framework + MongoDB用于许多应用程序。 In some instances, I need to respond with a JSON error message to the client making the request to display an internationalized error message. 在某些情况下,我需要向请求显示国际化错误消息的客户端响应JSON错误消息。
An error message will generally be a simple JSON: 错误消息通常是简单的JSON:
val errorMessage = ("error" -> "some error message");
This message would then be served via net.liftweb.rest.RestHelper
with yield requestParam: JValue
. 然后将通过net.liftweb.rest.RestHelper
和yield requestParam: JValue
提供此消息。 I use for comprehensions
to check for errors and return these JValue
s. 我for comprehensions
以检查错误并返回这些JValue
。
What is the best practice to store these messages in Scala(with internationalization in mind)? 将这些消息存储在Scala中的最佳实践是什么(考虑国际化)?
well, doesn't the principle "let the developer decide" apply? 好吧,“让开发者决定”的原则不适用吗? I mean, AFAIK, there is no central way to do that. 我的意思是,AFAIK没有做到这一点的中央方法。 Do any way you want. 随心所欲。 For example, (S ? "error") -> (S ? "my.error.reason123")
例如, (S ? "error") -> (S ? "my.error.reason123")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.