diff options
author | Jesús Espino <jespinog@gmail.com> | 2018-01-08 19:13:24 +0100 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2018-01-08 13:13:24 -0500 |
commit | dd9ad10d705fdbd7fbfa7323e6560b69021a2950 (patch) | |
tree | 4064e05fa746abae33fc7c6939fcdef2be7317d2 /model | |
parent | 591ef9f352efd98a85e6d04c0c9072c4c2987527 (diff) | |
download | chat-dd9ad10d705fdbd7fbfa7323e6560b69021a2950.tar.gz chat-dd9ad10d705fdbd7fbfa7323e6560b69021a2950.tar.bz2 chat-dd9ad10d705fdbd7fbfa7323e6560b69021a2950.zip |
[PLT-6936] Translate AppError.Message automatically by default (#8063)
Diffstat (limited to 'model')
-rw-r--r-- | model/utils.go | 12 |
1 files changed, 12 insertions, 0 deletions
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 } |