Using utils log reporting

This commit is contained in:
Brendan Abolivier 2017-07-10 14:18:15 +01:00
parent 86606e68eb
commit eaa21e2a1d
No known key found for this signature in database
GPG key ID: 8EF1500759F70623

View file

@ -49,7 +49,10 @@ func GetProfile(
} }
} }
localpart := getLocalPart(userID) localpart := getLocalPart(userID)
if profile, err := accountDB.GetProfileByLocalpart(localpart); err == nil { profile, err := accountDB.GetProfileByLocalpart(localpart)
if err != nil {
return httputil.LogThenError(req, err)
}
res := profileResponse{ res := profileResponse{
AvatarURL: profile.AvatarURL, AvatarURL: profile.AvatarURL,
DisplayName: profile.DisplayName, DisplayName: profile.DisplayName,
@ -59,11 +62,6 @@ func GetProfile(
JSON: res, JSON: res,
} }
} }
return util.JSONResponse{
Code: 500,
JSON: jsonerror.Unknown("Failed to load user profile"),
}
}
// GetAvatarURL implements GET /profile/{userID}/avatar_url // GetAvatarURL implements GET /profile/{userID}/avatar_url
func GetAvatarURL( func GetAvatarURL(
@ -112,10 +110,7 @@ func SetAvatarURL(
localpart := getLocalPart(userID) localpart := getLocalPart(userID)
if err := accountDB.SetAvatarURL(localpart, r.AvatarURL); err != nil { if err := accountDB.SetAvatarURL(localpart, r.AvatarURL); err != nil {
return util.JSONResponse{ return httputil.LogThenError(req, err)
Code: 500,
JSON: jsonerror.Unknown("Failed to set avatar URL"),
}
} }
return util.JSONResponse{ return util.JSONResponse{
Code: 200, Code: 200,
@ -170,10 +165,7 @@ func SetDisplayName(
localpart := getLocalPart(userID) localpart := getLocalPart(userID)
if err := accountDB.SetDisplayName(localpart, r.DisplayName); err != nil { if err := accountDB.SetDisplayName(localpart, r.DisplayName); err != nil {
return util.JSONResponse{ return httputil.LogThenError(req, err)
Code: 500,
JSON: jsonerror.Unknown("Failed to set display name"),
}
} }
return util.JSONResponse{ return util.JSONResponse{
Code: 200, Code: 200,