summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-08-31 15:03:16 +0100
committerJoram Wilander <jwawilander@gmail.com>2017-08-31 10:03:16 -0400
commit63b10be020deffecba0c5eef8e5872418215b464 (patch)
tree192c061ba8abc8c07b4241fa1d186c0152f8267a
parentb37e17c03259b592e0bc735d48d15d7cf34469e4 (diff)
downloadchat-63b10be020deffecba0c5eef8e5872418215b464.tar.gz
chat-63b10be020deffecba0c5eef8e5872418215b464.tar.bz2
chat-63b10be020deffecba0c5eef8e5872418215b464.zip
APIv4: NewLocAppError -> NewAppError (#7328)
-rw-r--r--api4/api.go3
-rw-r--r--api4/channel.go6
-rw-r--r--api4/context.go20
-rw-r--r--api4/file.go21
-rw-r--r--api4/reaction.go6
-rw-r--r--api4/team.go17
-rw-r--r--api4/user.go20
-rw-r--r--api4/webhook.go7
-rw-r--r--api4/websocket.go2
9 files changed, 34 insertions, 68 deletions
diff --git a/api4/api.go b/api4/api.go
index 6e9534d40..8ed94c193 100644
--- a/api4/api.go
+++ b/api4/api.go
@@ -237,9 +237,8 @@ func HandleEtag(etag string, routeName string, w http.ResponseWriter, r *http.Re
}
func Handle404(w http.ResponseWriter, r *http.Request) {
- err := model.NewLocAppError("Handle404", "api.context.404.app_error", nil, "")
+ err := model.NewAppError("Handle404", "api.context.404.app_error", nil, "", http.StatusNotFound)
err.Translate(utils.T)
- err.StatusCode = http.StatusNotFound
l4g.Debug("%v: code=404 ip=%v", r.URL.Path, utils.GetIpAddress(r))
diff --git a/api4/channel.go b/api4/channel.go
index 8e9a6d9d6..8a14b85bb 100644
--- a/api4/channel.go
+++ b/api4/channel.go
@@ -106,15 +106,13 @@ func updateChannel(c *Context, w http.ResponseWriter, r *http.Request) {
}
if oldChannel.DeleteAt > 0 {
- c.Err = model.NewLocAppError("updateChannel", "api.channel.update_channel.deleted.app_error", nil, "")
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("updateChannel", "api.channel.update_channel.deleted.app_error", nil, "", http.StatusBadRequest)
return
}
if oldChannel.Name == model.DEFAULT_CHANNEL {
if (len(channel.Name) > 0 && channel.Name != oldChannel.Name) || (len(channel.Type) > 0 && channel.Type != oldChannel.Type) {
- c.Err = model.NewLocAppError("updateChannel", "api.channel.update_channel.tried.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}, "")
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("updateChannel", "api.channel.update_channel.tried.app_error", map[string]interface{}{"Channel": model.DEFAULT_CHANNEL}, "", http.StatusBadRequest)
return
}
}
diff --git a/api4/context.go b/api4/context.go
index e95e29991..3ea67b30c 100644
--- a/api4/context.go
+++ b/api4/context.go
@@ -113,7 +113,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if h.requireSession && !h.trustRequester {
if r.Header.Get(model.HEADER_REQUESTED_WITH) != model.HEADER_REQUESTED_WITH_XML {
- c.Err = model.NewLocAppError("ServeHTTP", "api.context.session_expired.app_error", nil, "token="+token+" Appears to be a CSRF attempt")
+ c.Err = model.NewAppError("ServeHTTP", "api.context.session_expired.app_error", nil, "token="+token+" Appears to be a CSRF attempt", http.StatusUnauthorized)
token = ""
}
}
@@ -144,12 +144,10 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
l4g.Error(utils.T("api.context.invalid_session.error"), err.Error())
c.RemoveSessionCookie(w, r)
if h.requireSession {
- c.Err = model.NewLocAppError("ServeHTTP", "api.context.session_expired.app_error", nil, "token="+token)
- c.Err.StatusCode = http.StatusUnauthorized
+ c.Err = model.NewAppError("ServeHTTP", "api.context.session_expired.app_error", nil, "token="+token, http.StatusUnauthorized)
}
} else if !session.IsOAuth && isTokenFromQueryString {
- c.Err = model.NewLocAppError("ServeHTTP", "api.context.token_provided.app_error", nil, "token="+token)
- c.Err.StatusCode = http.StatusUnauthorized
+ c.Err = model.NewAppError("ServeHTTP", "api.context.token_provided.app_error", nil, "token="+token, http.StatusUnauthorized)
} else {
c.Session = *session
}
@@ -262,8 +260,7 @@ func (c *Context) MfaRequired() {
}
if user, err := app.GetUser(c.Session.UserId); err != nil {
- c.Err = model.NewLocAppError("", "api.context.session_expired.app_error", nil, "MfaRequired")
- c.Err.StatusCode = http.StatusUnauthorized
+ c.Err = model.NewAppError("", "api.context.session_expired.app_error", nil, "MfaRequired", http.StatusUnauthorized)
return
} else {
// Only required for email and ldap accounts
@@ -306,19 +303,16 @@ func (c *Context) SetInvalidUrlParam(parameter string) {
}
func NewInvalidParamError(parameter string) *model.AppError {
- err := model.NewLocAppError("Context", "api.context.invalid_body_param.app_error", map[string]interface{}{"Name": parameter}, "")
- err.StatusCode = http.StatusBadRequest
+ err := model.NewAppError("Context", "api.context.invalid_body_param.app_error", map[string]interface{}{"Name": parameter}, "", http.StatusBadRequest)
return err
}
func NewInvalidUrlParamError(parameter string) *model.AppError {
- err := model.NewLocAppError("Context", "api.context.invalid_url_param.app_error", map[string]interface{}{"Name": parameter}, "")
- err.StatusCode = http.StatusBadRequest
+ err := model.NewAppError("Context", "api.context.invalid_url_param.app_error", map[string]interface{}{"Name": parameter}, "", http.StatusBadRequest)
return err
}
func (c *Context) SetPermissionError(permission *model.Permission) {
- c.Err = model.NewLocAppError("Permissions", "api.context.permissions.app_error", nil, "userId="+c.Session.UserId+", "+"permission="+permission.Id)
- c.Err.StatusCode = http.StatusForbidden
+ c.Err = model.NewAppError("Permissions", "api.context.permissions.app_error", nil, "userId="+c.Session.UserId+", "+"permission="+permission.Id, http.StatusForbidden)
}
func (c *Context) SetSiteURLHeader(url string) {
diff --git a/api4/file.go b/api4/file.go
index 7dc13dafc..ab71b998b 100644
--- a/api4/file.go
+++ b/api4/file.go
@@ -160,8 +160,7 @@ func getFileThumbnail(c *Context, w http.ResponseWriter, r *http.Request) {
}
if info.ThumbnailPath == "" {
- c.Err = model.NewLocAppError("getFileThumbnail", "api.file.get_file_thumbnail.no_thumbnail.app_error", nil, "file_id="+info.Id)
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("getFileThumbnail", "api.file.get_file_thumbnail.no_thumbnail.app_error", nil, "file_id="+info.Id, http.StatusBadRequest)
return
}
@@ -181,8 +180,7 @@ func getFileLink(c *Context, w http.ResponseWriter, r *http.Request) {
}
if !utils.Cfg.FileSettings.EnablePublicLink {
- c.Err = model.NewLocAppError("getPublicLink", "api.file.get_public_link.disabled.app_error", nil, "")
- c.Err.StatusCode = http.StatusNotImplemented
+ c.Err = model.NewAppError("getPublicLink", "api.file.get_public_link.disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -198,8 +196,7 @@ func getFileLink(c *Context, w http.ResponseWriter, r *http.Request) {
}
if len(info.PostId) == 0 {
- c.Err = model.NewLocAppError("getPublicLink", "api.file.get_public_link.no_post.app_error", nil, "file_id="+info.Id)
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("getPublicLink", "api.file.get_public_link.no_post.app_error", nil, "file_id="+info.Id, http.StatusBadRequest)
return
}
@@ -232,8 +229,7 @@ func getFilePreview(c *Context, w http.ResponseWriter, r *http.Request) {
}
if info.PreviewPath == "" {
- c.Err = model.NewLocAppError("getFilePreview", "api.file.get_file_preview.no_preview.app_error", nil, "file_id="+info.Id)
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("getFilePreview", "api.file.get_file_preview.no_preview.app_error", nil, "file_id="+info.Id, http.StatusBadRequest)
return
}
@@ -274,8 +270,7 @@ func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) {
}
if !utils.Cfg.FileSettings.EnablePublicLink {
- c.Err = model.NewLocAppError("getPublicFile", "api.file.get_public_link.disabled.app_error", nil, "")
- c.Err.StatusCode = http.StatusNotImplemented
+ c.Err = model.NewAppError("getPublicFile", "api.file.get_public_link.disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -288,14 +283,12 @@ func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) {
hash := r.URL.Query().Get("h")
if len(hash) == 0 {
- c.Err = model.NewLocAppError("getPublicFile", "api.file.get_file.public_invalid.app_error", nil, "")
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("getPublicFile", "api.file.get_file.public_invalid.app_error", nil, "", http.StatusBadRequest)
return
}
if hash != app.GeneratePublicLinkHash(info.Id, *utils.Cfg.FileSettings.PublicLinkSalt) {
- c.Err = model.NewLocAppError("getPublicFile", "api.file.get_file.public_invalid.app_error", nil, "")
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("getPublicFile", "api.file.get_file.public_invalid.app_error", nil, "", http.StatusBadRequest)
return
}
diff --git a/api4/reaction.go b/api4/reaction.go
index 6605eb070..7f161d7fe 100644
--- a/api4/reaction.go
+++ b/api4/reaction.go
@@ -28,14 +28,12 @@ func saveReaction(c *Context, w http.ResponseWriter, r *http.Request) {
}
if len(reaction.UserId) != 26 || len(reaction.PostId) != 26 || len(reaction.EmojiName) == 0 || len(reaction.EmojiName) > 64 {
- c.Err = model.NewLocAppError("saveReaction", "api.reaction.save_reaction.invalid.app_error", nil, "")
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("saveReaction", "api.reaction.save_reaction.invalid.app_error", nil, "", http.StatusBadRequest)
return
}
if reaction.UserId != c.Session.UserId {
- c.Err = model.NewLocAppError("saveReaction", "api.reaction.save_reaction.user_id.app_error", nil, "")
- c.Err.StatusCode = http.StatusForbidden
+ c.Err = model.NewAppError("saveReaction", "api.reaction.save_reaction.user_id.app_error", nil, "", http.StatusForbidden)
return
}
diff --git a/api4/team.go b/api4/team.go
index b71b285e6..656c4dbbc 100644
--- a/api4/team.go
+++ b/api4/team.go
@@ -603,7 +603,7 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := r.ParseMultipartForm(10000000); err != nil {
- c.Err = model.NewLocAppError("importTeam", "api.team.import_team.parse.app_error", nil, err.Error())
+ c.Err = model.NewAppError("importTeam", "api.team.import_team.parse.app_error", nil, err.Error(), http.StatusInternalServerError)
return
}
@@ -612,28 +612,24 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
fileSizeStr, ok := r.MultipartForm.Value["filesize"]
if !ok {
- c.Err = model.NewLocAppError("importTeam", "api.team.import_team.unavailable.app_error", nil, "")
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("importTeam", "api.team.import_team.unavailable.app_error", nil, "", http.StatusBadRequest)
return
}
fileSize, err := strconv.ParseInt(fileSizeStr[0], 10, 64)
if err != nil {
- c.Err = model.NewLocAppError("importTeam", "api.team.import_team.integer.app_error", nil, "")
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("importTeam", "api.team.import_team.integer.app_error", nil, "", http.StatusBadRequest)
return
}
fileInfoArray, ok := r.MultipartForm.File["file"]
if !ok {
- c.Err = model.NewLocAppError("importTeam", "api.team.import_team.no_file.app_error", nil, "")
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("importTeam", "api.team.import_team.no_file.app_error", nil, "", http.StatusBadRequest)
return
}
if len(fileInfoArray) <= 0 {
- c.Err = model.NewLocAppError("importTeam", "api.team.import_team.array.app_error", nil, "")
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("importTeam", "api.team.import_team.array.app_error", nil, "", http.StatusBadRequest)
return
}
@@ -642,8 +638,7 @@ func importTeam(c *Context, w http.ResponseWriter, r *http.Request) {
fileData, err := fileInfo.Open()
defer fileData.Close()
if err != nil {
- c.Err = model.NewLocAppError("importTeam", "api.team.import_team.open.app_error", nil, err.Error())
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("importTeam", "api.team.import_team.open.app_error", nil, err.Error(), http.StatusBadRequest)
return
}
diff --git a/api4/user.go b/api4/user.go
index 2f1c72957..889fe56a3 100644
--- a/api4/user.go
+++ b/api4/user.go
@@ -234,19 +234,17 @@ func setProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
}
if len(*utils.Cfg.FileSettings.DriverName) == 0 {
- c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.storage.app_error", nil, "")
- c.Err.StatusCode = http.StatusNotImplemented
+ c.Err = model.NewAppError("uploadProfileImage", "api.user.upload_profile_user.storage.app_error", nil, "", http.StatusNotImplemented)
return
}
if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize {
- c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.too_large.app_error", nil, "")
- c.Err.StatusCode = http.StatusRequestEntityTooLarge
+ c.Err = model.NewAppError("uploadProfileImage", "api.user.upload_profile_user.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)
return
}
if err := r.ParseMultipartForm(*utils.Cfg.FileSettings.MaxFileSize); err != nil {
- c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.parse.app_error", nil, "")
+ c.Err = model.NewAppError("uploadProfileImage", "api.user.upload_profile_user.parse.app_error", nil, "", http.StatusInternalServerError)
return
}
@@ -254,14 +252,12 @@ func setProfileImage(c *Context, w http.ResponseWriter, r *http.Request) {
imageArray, ok := m.File["image"]
if !ok {
- c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.no_file.app_error", nil, "")
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("uploadProfileImage", "api.user.upload_profile_user.no_file.app_error", nil, "", http.StatusBadRequest)
return
}
if len(imageArray) <= 0 {
- c.Err = model.NewLocAppError("uploadProfileImage", "api.user.upload_profile_user.array.app_error", nil, "")
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("uploadProfileImage", "api.user.upload_profile_user.array.app_error", nil, "", http.StatusBadRequest)
return
}
@@ -650,8 +646,7 @@ func updateUserActive(c *Context, w http.ResponseWriter, r *http.Request) {
isSelfDeactive := !active && c.Params.UserId == c.Session.UserId
if !isSelfDeactive && !app.SessionHasPermissionTo(c.Session, model.PERMISSION_MANAGE_SYSTEM) {
- c.Err = model.NewLocAppError("updateUserActive", "api.user.update_active.permissions.app_error", nil, "userId="+c.Params.UserId)
- c.Err.StatusCode = http.StatusForbidden
+ c.Err = model.NewAppError("updateUserActive", "api.user.update_active.permissions.app_error", nil, "userId="+c.Params.UserId, http.StatusForbidden)
return
}
@@ -1014,8 +1009,7 @@ func verifyUserEmail(c *Context, w http.ResponseWriter, r *http.Request) {
}
if err := app.VerifyEmailFromToken(token); err != nil {
- c.Err = model.NewLocAppError("verifyUserEmail", "api.user.verify_email.bad_link.app_error", nil, err.Error())
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("verifyUserEmail", "api.user.verify_email.bad_link.app_error", nil, err.Error(), http.StatusBadRequest)
return
} else {
c.LogAudit("Email Verified")
diff --git a/api4/webhook.go b/api4/webhook.go
index 91241a017..6d332e8fc 100644
--- a/api4/webhook.go
+++ b/api4/webhook.go
@@ -466,12 +466,7 @@ func incomingWebhook(c *Context, w http.ResponseWriter, r *http.Request) {
utils.T("api.webhook.incoming.debug"),
)
if err != nil {
- c.Err = model.NewLocAppError(
- "incomingWebhook",
- "api.webhook.incoming.debug.error",
- nil,
- err.Error(),
- )
+ c.Err = model.NewAppError("incomingWebhook", "api.webhook.incoming.debug.error", nil, err.Error(), http.StatusInternalServerError)
return
}
}
diff --git a/api4/websocket.go b/api4/websocket.go
index 1caef6c4a..fade548cb 100644
--- a/api4/websocket.go
+++ b/api4/websocket.go
@@ -31,7 +31,7 @@ func connectWebSocket(c *Context, w http.ResponseWriter, r *http.Request) {
ws, err := upgrader.Upgrade(w, r, nil)
if err != nil {
l4g.Error(utils.T("api.web_socket.connect.error"), err)
- c.Err = model.NewLocAppError("connect", "api.web_socket.connect.upgrade.app_error", nil, "")
+ c.Err = model.NewAppError("connect", "api.web_socket.connect.upgrade.app_error", nil, "", http.StatusInternalServerError)
return
}