summaryrefslogtreecommitdiffstats
path: root/api/file.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-09-01 14:58:43 +0100
committerJoram Wilander <jwawilander@gmail.com>2017-09-01 09:58:43 -0400
commit75c63344def7a108f1257b99e0342330da882a38 (patch)
treea5090e735eacf2d4dea4877a3b84e1f276e1f66b /api/file.go
parent718da3593b6feb1c3546b1e17c30c22990157ed5 (diff)
downloadchat-75c63344def7a108f1257b99e0342330da882a38.tar.gz
chat-75c63344def7a108f1257b99e0342330da882a38.tar.bz2
chat-75c63344def7a108f1257b99e0342330da882a38.zip
Api: NewLocAppError -> NewAppError (#7280)
Diffstat (limited to 'api/file.go')
-rw-r--r--api/file.go42
1 files changed, 14 insertions, 28 deletions
diff --git a/api/file.go b/api/file.go
index 43814d8f4..c7ed15a33 100644
--- a/api/file.go
+++ b/api/file.go
@@ -52,8 +52,7 @@ func uploadFile(c *Context, w http.ResponseWriter, r *http.Request) {
}
if r.ContentLength > *utils.Cfg.FileSettings.MaxFileSize {
- c.Err = model.NewLocAppError("uploadFile", "api.file.upload_file.too_large.app_error", nil, "")
- c.Err.StatusCode = http.StatusRequestEntityTooLarge
+ c.Err = model.NewAppError("uploadFile", "api.file.upload_file.too_large.app_error", nil, "", http.StatusRequestEntityTooLarge)
return
}
@@ -113,8 +112,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
}
@@ -135,8 +133,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
}
@@ -163,8 +160,7 @@ func getFileInfo(c *Context, w http.ResponseWriter, r *http.Request) {
func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) {
if !utils.Cfg.FileSettings.EnablePublicLink {
- c.Err = model.NewLocAppError("getPublicFile", "api.file.get_file.public_disabled.app_error", nil, "")
- c.Err.StatusCode = http.StatusNotImplemented
+ c.Err = model.NewAppError("getPublicFile", "api.file.get_file.public_disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -180,13 +176,11 @@ func getPublicFile(c *Context, w http.ResponseWriter, r *http.Request) {
correctHash := app.GeneratePublicLinkHash(info.Id, *utils.Cfg.FileSettings.PublicLinkSalt)
if hash != correctHash {
- 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
}
} else {
- 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
}
@@ -219,8 +213,7 @@ func getFileInfoForRequest(c *Context, r *http.Request, requireFileVisible bool)
// only let users access files visible in a channel, unless they're the one who uploaded the file
if info.CreatorId != c.Session.UserId {
if len(info.PostId) == 0 {
- err := model.NewLocAppError("getFileInfoForRequest", "api.file.get_file_info_for_request.no_post.app_error", nil, "file_id="+fileId)
- err.StatusCode = http.StatusBadRequest
+ err := model.NewAppError("getFileInfoForRequest", "api.file.get_file_info_for_request.no_post.app_error", nil, "file_id="+fileId, http.StatusBadRequest)
return nil, err
}
@@ -237,12 +230,10 @@ func getFileInfoForRequest(c *Context, r *http.Request, requireFileVisible bool)
func getPublicFileOld(c *Context, w http.ResponseWriter, r *http.Request) {
if len(*utils.Cfg.FileSettings.DriverName) == 0 {
- c.Err = model.NewLocAppError("getPublicFile", "api.file.get_public_file_old.storage.app_error", nil, "")
- c.Err.StatusCode = http.StatusNotImplemented
+ c.Err = model.NewAppError("getPublicFile", "api.file.get_public_file_old.storage.app_error", nil, "", http.StatusNotImplemented)
return
} else if !utils.Cfg.FileSettings.EnablePublicLink {
- c.Err = model.NewLocAppError("getPublicFile", "api.file.get_file.public_disabled.app_error", nil, "")
- c.Err.StatusCode = http.StatusNotImplemented
+ c.Err = model.NewAppError("getPublicFile", "api.file.get_file.public_disabled.app_error", nil, "", http.StatusNotImplemented)
return
}
@@ -259,13 +250,11 @@ func getPublicFileOld(c *Context, w http.ResponseWriter, r *http.Request) {
correctHash := app.GeneratePublicLinkHash(filename, *utils.Cfg.FileSettings.PublicLinkSalt)
if hash != correctHash {
- 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
}
} else {
- 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
}
@@ -280,8 +269,7 @@ func getPublicFileOld(c *Context, w http.ResponseWriter, r *http.Request) {
}
if len(info.PostId) == 0 {
- c.Err = model.NewLocAppError("getPublicFileOld", "api.file.get_public_file_old.no_post.app_error", nil, "file_id="+info.Id)
- c.Err.StatusCode = http.StatusBadRequest
+ c.Err = model.NewAppError("getPublicFileOld", "api.file.get_public_file_old.no_post.app_error", nil, "file_id="+info.Id, http.StatusBadRequest)
return
}
@@ -325,8 +313,7 @@ func writeFileResponse(filename string, contentType string, bytes []byte, w http
func getPublicLink(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
}
@@ -337,8 +324,7 @@ func getPublicLink(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
}