Этот коммит содержится в:
=Corey Hulen
2016-01-20 14:36:34 -06:00
родитель d703d09063
Коммит 984fa7f1ca
7 изменённых файлов: 48 добавлений и 13 удалений

Просмотреть файл

@@ -41,7 +41,7 @@ func getLogs(c *Context, w http.ResponseWriter, r *http.Request) {
file, err := os.Open(utils.GetLogFileLocation(utils.Cfg.LogSettings.FileLocation)) file, err := os.Open(utils.GetLogFileLocation(utils.Cfg.LogSettings.FileLocation))
if err != nil { if err != nil {
c.Err = model.NewAppError("getLogs", c.T("api.admin.file_read_error"), err.Error()) c.Err = model.NewLocAppError("getLogs", "api.admin.file_read_error", nil, err.Error())
} }
defer file.Close() defer file.Close()

Просмотреть файл

@@ -14,6 +14,7 @@ var Client *model.Client
func Setup() { func Setup() {
if Srv == nil { if Srv == nil {
utils.LoadConfig("config.json") utils.LoadConfig("config.json")
utils.InitTranslations()
utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
NewServer() NewServer()
StartServer() StartServer()

Просмотреть файл

@@ -206,6 +206,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
} }
if c.Err != nil { if c.Err != nil {
c.Err.Translate(c.T)
c.Err.RequestId = c.RequestId c.Err.RequestId = c.RequestId
c.LogError(c.Err) c.LogError(c.Err)
c.Err.Where = r.URL.Path c.Err.Where = r.URL.Path
@@ -373,7 +374,7 @@ func (c *Context) RemoveSessionCookie(w http.ResponseWriter, r *http.Request) {
} }
func (c *Context) SetInvalidParam(where string, name string) { func (c *Context) SetInvalidParam(where string, name string) {
c.Err = model.NewAppError(where, "Invalid "+name+" parameter", "") c.Err = model.NewLocAppError(where, "api.context.invalid_param", map[string]interface{}{"Name": name}, "")
c.Err.StatusCode = http.StatusBadRequest c.Err.StatusCode = http.StatusBadRequest
} }

Просмотреть файл

@@ -10,5 +10,9 @@
{ {
"id": "api.admin.file_read_error", "id": "api.admin.file_read_error",
"translation": "Error reading log file" "translation": "Error reading log file"
},
{
"id": "api.context.invalid_param",
"translation": "Invalid {{.Name}} parameter"
} }
] ]

Просмотреть файл

@@ -1,14 +1,18 @@
[ [
{ {
"id": "utils.i18n.loaded", "id": "utils.i18n.loaded",
"translation": "Loaded system translations for '%v' from '%v'" "translation": "Loaded system translations for '%v' from '%v' spanish test!"
}, },
{ {
"id": "mattermost.current_version", "id": "mattermost.current_version",
"translation": "Current version is %v (%v/%v/%v)" "translation": "Current version is %v (%v/%v/%v) spanish test!"
}, },
{ {
"id": "api.admin.file_read_error", "id": "api.admin.file_read_error",
"translation": "Error reading log file" "translation": "Error reading log file spanish test!"
},
{
"id": "api.context.invalid_param",
"translation": "Invalid {{.Name}} parameter spanish test!"
} }
] ]

Просмотреть файл

@@ -9,13 +9,15 @@ import (
"encoding/base32" "encoding/base32"
"encoding/json" "encoding/json"
"fmt" "fmt"
"github.com/pborman/uuid"
"io" "io"
"net/mail" "net/mail"
"net/url" "net/url"
"regexp" "regexp"
"strings" "strings"
"time" "time"
goi18n "github.com/nicksnyder/go-i18n/i18n"
"github.com/pborman/uuid"
) )
type StringInterface map[string]interface{} 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. // AppError is returned for any http response that's not in the 200 range.
type AppError struct { type AppError struct {
Message string `json:"message"` // Message to be display to the end user without debugging information LocId string `json:"loc_id"` // Message to be display to the end user without debugging information
DetailedError string `json:"detailed_error"` // Internal error string to help the developer Message string `json:"message"` // Message to be display to the end user without debugging information
RequestId string `json:"request_id"` // The RequestId that's also set in the header DetailedError string `json:"detailed_error"` // Internal error string to help the developer
StatusCode int `json:"status_code"` // The http status code RequestId string `json:"request_id"` // The RequestId that's also set in the header
Where string `json:"-"` // The function where it happened in the form of Struct.Func StatusCode int `json:"status_code"` // The http status code
IsOAuth bool `json:"is_oauth"` // Whether the error is OAuth specific 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 { func (er *AppError) Error() string {
return er.Where + ": " + er.Message + ", " + er.DetailedError 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 { func (er *AppError) ToJson() string {
b, err := json.Marshal(er) b, err := json.Marshal(er)
if err != nil { if err != nil {
@@ -68,6 +82,17 @@ func NewAppError(where string, message string, details string) *AppError {
return ap 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") var encoding = base32.NewEncoding("ybndrfg8ejkmcpqxot1uwisza345h769")
// NewId is a globally unique identifier. It is a [A-Z0-9] string 26 // NewId is a globally unique identifier. It is a [A-Z0-9] string 26

Просмотреть файл

@@ -28,7 +28,7 @@ var CurrentVersion string = versions[0]
var BuildNumber = "_BUILD_NUMBER_" var BuildNumber = "_BUILD_NUMBER_"
var BuildDate = "_BUILD_DATE_" var BuildDate = "_BUILD_DATE_"
var BuildHash = "_BUILD_HASH_" var BuildHash = "_BUILD_HASH_"
var BuildEnterpriseReady = "_BUILD_ENTERPRISE_READY_" var BuildEnterpriseReady = "false"
func SplitVersion(version string) (int64, int64, int64) { func SplitVersion(version string) (int64, int64, int64) {
parts := strings.Split(version, ".") parts := strings.Split(version, ".")