From 21b1cd44e09c41ea581ee05de46db5e5f3fa1696 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 13 Apr 2018 10:57:22 -0400 Subject: [PATCH] Fix error handling when requesting profile image for bad user ID (#8618) --- api4/user.go | 3 ++- api4/user_test.go | 3 +++ i18n/en.json | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/api4/user.go b/api4/user.go index 20b035f1d5..9aa709db54 100644 --- a/api4/user.go +++ b/api4/user.go @@ -199,7 +199,8 @@ func getProfileImage(c *Context, w http.ResponseWriter, r *http.Request) { return } else { if len(users) == 0 { - c.Err = err + c.Err = model.NewAppError("getProfileImage", "api.user.get_profile_image.not_found.app_error", nil, "", http.StatusNotFound) + return } user := users[0] diff --git a/api4/user_test.go b/api4/user_test.go index 359756aeb6..27219726bd 100644 --- a/api4/user_test.go +++ b/api4/user_test.go @@ -834,6 +834,9 @@ func TestGetProfileImage(t *testing.T) { _, resp = Client.GetProfileImage("junk", "") CheckBadRequestStatus(t, resp) + _, resp = Client.GetProfileImage(model.NewId(), "") + CheckNotFoundStatus(t, resp) + Client.Logout() _, resp = Client.GetProfileImage(user.Id, "") CheckUnauthorizedStatus(t, resp) diff --git a/i18n/en.json b/i18n/en.json index 7abe67567a..02ac46e70e 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -3094,6 +3094,10 @@ "id": "api.user.upload_profile_user.parse.app_error", "translation": "Could not parse multipart form" }, + { + "id": "api.user.get_profile_image.not_found.app_error", + "translation": "Unable to get profile image, user not found." + }, { "id": "api.user.upload_profile_user.storage.app_error", "translation": "Unable to upload file. Image storage is not configured."