Improved error handling/reporting

This commit is contained in:
Brendan Abolivier 2017-07-10 12:04:24 +01:00
parent c4d1af68b1
commit 86606e68eb
No known key found for this signature in database
GPG key ID: 8EF1500759F70623

View file

@ -76,18 +76,16 @@ func GetAvatarURL(
} }
} }
localpart := getLocalPart(userID) localpart := getLocalPart(userID)
if profile, err := accountDB.GetProfileByLocalpart(localpart); err == nil { profile, err := accountDB.GetProfileByLocalpart(localpart)
res := avatarURL{ if err != nil {
AvatarURL: profile.AvatarURL, return httputil.LogThenError(req, err)
} }
return util.JSONResponse{ res := avatarURL{
Code: 200, AvatarURL: profile.AvatarURL,
JSON: res,
}
} }
return util.JSONResponse{ return util.JSONResponse{
Code: 500, Code: 200,
JSON: jsonerror.Unknown("Failed to load avatar URL"), JSON: res,
} }
} }
@ -125,7 +123,7 @@ func SetAvatarURL(
} }
} }
// SetDisplayName implements GET /profile/{userID}/displayname // GetDisplayName implements GET /profile/{userID}/displayname
func GetDisplayName( func GetDisplayName(
req *http.Request, accountDB *accounts.Database, userID string, req *http.Request, accountDB *accounts.Database, userID string,
) util.JSONResponse { ) util.JSONResponse {
@ -136,18 +134,16 @@ func GetDisplayName(
} }
} }
localpart := getLocalPart(userID) localpart := getLocalPart(userID)
if profile, err := accountDB.GetProfileByLocalpart(localpart); err == nil { profile, err := accountDB.GetProfileByLocalpart(localpart)
res := displayName{ if err != nil {
DisplayName: profile.DisplayName, return httputil.LogThenError(req, err)
} }
return util.JSONResponse{ res := displayName{
Code: 200, DisplayName: profile.DisplayName,
JSON: res,
}
} }
return util.JSONResponse{ return util.JSONResponse{
Code: 500, Code: 200,
JSON: jsonerror.Unknown("Failed to load display name"), JSON: res,
} }
} }