From dd9ad10d705fdbd7fbfa7323e6560b69021a2950 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Espino?= Date: Mon, 8 Jan 2018 19:13:24 +0100 Subject: [PLT-6936] Translate AppError.Message automatically by default (#8063) --- model/utils.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'model') diff --git a/model/utils.go b/model/utils.go index e84d44f72..648e67c75 100644 --- a/model/utils.go +++ b/model/utils.go @@ -36,6 +36,12 @@ type StringInterface map[string]interface{} type StringMap map[string]string type StringArray []string +var translateFunc goi18n.TranslateFunc = nil + +func AppErrorInit(t goi18n.TranslateFunc) { + translateFunc = t +} + type AppError struct { Id string `json:"id"` Message string `json:"message"` // Message to be display to the end user without debugging information @@ -52,6 +58,11 @@ func (er *AppError) Error() string { } func (er *AppError) Translate(T goi18n.TranslateFunc) { + if T == nil { + er.Message = er.Id + return + } + if er.params == nil { er.Message = T(er.Id) } else { @@ -105,6 +116,7 @@ func NewAppError(where string, id string, params map[string]interface{}, details ap.DetailedError = details ap.StatusCode = status ap.IsOAuth = false + ap.Translate(translateFunc) return ap } -- cgit v1.2.3-1-g7c22