From 984fa7f1ca1b582f77cc511156e9747b175203e5 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 20 Jan 2016 14:36:34 -0600 Subject: PLT-7-server-db --- model/utils.go | 39 ++++++++++++++++++++++++++++++++------- model/version.go | 2 +- 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'model') diff --git a/model/utils.go b/model/utils.go index 617c95efd..0d26fd3ba 100644 --- a/model/utils.go +++ b/model/utils.go @@ -9,13 +9,15 @@ import ( "encoding/base32" "encoding/json" "fmt" - "github.com/pborman/uuid" "io" "net/mail" "net/url" "regexp" "strings" "time" + + goi18n "github.com/nicksnyder/go-i18n/i18n" + "github.com/pborman/uuid" ) type StringInterface map[string]interface{} @@ -25,18 +27,30 @@ type EncryptStringMap map[string]string // AppError is returned for any http response that's not in the 200 range. type AppError struct { - Message string `json:"message"` // Message to be display to the end user without debugging information - DetailedError string `json:"detailed_error"` // Internal error string to help the developer - RequestId string `json:"request_id"` // The RequestId that's also set in the header - StatusCode int `json:"status_code"` // The http status code - Where string `json:"-"` // The function where it happened in the form of Struct.Func - IsOAuth bool `json:"is_oauth"` // Whether the error is OAuth specific + LocId string `json:"loc_id"` // Message to be display to the end user without debugging information + Message string `json:"message"` // Message to be display to the end user without debugging information + DetailedError string `json:"detailed_error"` // Internal error string to help the developer + RequestId string `json:"request_id"` // The RequestId that's also set in the header + StatusCode int `json:"status_code"` // The http status code + Where string `json:"-"` // The function where it happened in the form of Struct.Func + IsOAuth bool `json:"is_oauth"` // Whether the error is OAuth specific + params map[string]interface{} `json:"-"` } func (er *AppError) Error() string { return er.Where + ": " + er.Message + ", " + er.DetailedError } +func (er *AppError) Translate(T goi18n.TranslateFunc) { + if len(er.Message) == 0 { + if er.params == nil { + er.Message = T(er.LocId) + } else { + er.Message = T(er.LocId, er.params) + } + } +} + func (er *AppError) ToJson() string { b, err := json.Marshal(er) if err != nil { @@ -68,6 +82,17 @@ func NewAppError(where string, message string, details string) *AppError { return ap } +func NewLocAppError(where string, locId string, params map[string]interface{}, details string) *AppError { + ap := &AppError{} + ap.LocId = locId + ap.params = params + ap.Where = where + ap.DetailedError = details + ap.StatusCode = 500 + ap.IsOAuth = false + return ap +} + var encoding = base32.NewEncoding("ybndrfg8ejkmcpqxot1uwisza345h769") // NewId is a globally unique identifier. It is a [A-Z0-9] string 26 diff --git a/model/version.go b/model/version.go index 88334ceea..f503ddb84 100644 --- a/model/version.go +++ b/model/version.go @@ -28,7 +28,7 @@ var CurrentVersion string = versions[0] var BuildNumber = "_BUILD_NUMBER_" var BuildDate = "_BUILD_DATE_" var BuildHash = "_BUILD_HASH_" -var BuildEnterpriseReady = "_BUILD_ENTERPRISE_READY_" +var BuildEnterpriseReady = "false" func SplitVersion(version string) (int64, int64, int64) { parts := strings.Split(version, ".") -- cgit v1.2.3-1-g7c22 From e70428c1bdb335f691a7740d15ed845f07670909 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 20 Jan 2016 14:38:17 -0600 Subject: tweak --- model/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'model') diff --git a/model/version.go b/model/version.go index f503ddb84..88334ceea 100644 --- a/model/version.go +++ b/model/version.go @@ -28,7 +28,7 @@ var CurrentVersion string = versions[0] var BuildNumber = "_BUILD_NUMBER_" var BuildDate = "_BUILD_DATE_" var BuildHash = "_BUILD_HASH_" -var BuildEnterpriseReady = "false" +var BuildEnterpriseReady = "_BUILD_ENTERPRISE_READY_" func SplitVersion(version string) (int64, int64, int64) { parts := strings.Split(version, ".") -- cgit v1.2.3-1-g7c22 From d74e2f3e1146efd80d4eeee36cf5c53e68b31fcc Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 20 Jan 2016 14:53:12 -0600 Subject: tweaking --- model/utils.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'model') diff --git a/model/utils.go b/model/utils.go index 0d26fd3ba..a18ca760e 100644 --- a/model/utils.go +++ b/model/utils.go @@ -25,9 +25,8 @@ type StringMap map[string]string type StringArray []string type EncryptStringMap map[string]string -// AppError is returned for any http response that's not in the 200 range. type AppError struct { - LocId string `json:"loc_id"` // Message to be display to the end user without debugging information + Id string `json:"id"` Message string `json:"message"` // Message to be display to the end user without debugging information DetailedError string `json:"detailed_error"` // Internal error string to help the developer RequestId string `json:"request_id"` // The RequestId that's also set in the header @@ -44,9 +43,9 @@ func (er *AppError) Error() string { func (er *AppError) Translate(T goi18n.TranslateFunc) { if len(er.Message) == 0 { if er.params == nil { - er.Message = T(er.LocId) + er.Message = T(er.Id) } else { - er.Message = T(er.LocId, er.params) + er.Message = T(er.Id, er.params) } } } @@ -82,9 +81,9 @@ func NewAppError(where string, message string, details string) *AppError { return ap } -func NewLocAppError(where string, locId string, params map[string]interface{}, details string) *AppError { +func NewLocAppError(where string, id string, params map[string]interface{}, details string) *AppError { ap := &AppError{} - ap.LocId = locId + ap.Id = id ap.params = params ap.Where = where ap.DetailedError = details -- cgit v1.2.3-1-g7c22