我想知道如何在具有多种语言的API中管理错误。
我知道有多种方法可以做到这一点。我找到了3。
针对所有语言发送错误,例如:
{
en:"error is....",
fr:"l'erreur est...",
...
}
以正确的语言发送一个错误
{
en:"error is...."
}
所有这些都有优点和缺点...
第一个:
+ API just manage statusCode and front(s) can manage error how it want
- API must manage dynamics error and send extra data
- Front must reformat the error (error + extra data)
others ?
第二个:
+ error message can just be displayed on front without update it (but need to get the good one for the language client)
- back must manage error message for all language (if there are 10-50 or more language it's a little bit annoying)
- back end must take care of displaying message interstanding for a user (I think it's not is role)
others ?
第三个:
+ error message can just be displayed on front without update it
- back end must take care of displaying message interstanding for a user (I think it's not is role)
- front must send the user's language at the session's begining and update this information if user change it
others ?
我认为第三个更好,但我不知道。 有人会说我什么是最好的解决方案,为什么?
预先感谢:)