summaryrefslogtreecommitdiffstats
path: root/model/utils.go
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-01-08 19:13:24 +0100
committerJoram Wilander <jwawilander@gmail.com>2018-01-08 13:13:24 -0500
commitdd9ad10d705fdbd7fbfa7323e6560b69021a2950 (patch)
tree4064e05fa746abae33fc7c6939fcdef2be7317d2 /model/utils.go
parent591ef9f352efd98a85e6d04c0c9072c4c2987527 (diff)
downloadchat-dd9ad10d705fdbd7fbfa7323e6560b69021a2950.tar.gz
chat-dd9ad10d705fdbd7fbfa7323e6560b69021a2950.tar.bz2
chat-dd9ad10d705fdbd7fbfa7323e6560b69021a2950.zip
[PLT-6936] Translate AppError.Message automatically by default (#8063)
Diffstat (limited to 'model/utils.go')
-rw-r--r--model/utils.go12
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
}