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,7 +76,10 @@ func GetAvatarURL(
} }
} }
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 := avatarURL{ res := avatarURL{
AvatarURL: profile.AvatarURL, AvatarURL: profile.AvatarURL,
} }
@ -84,11 +87,6 @@ func GetAvatarURL(
Code: 200, Code: 200,
JSON: res, JSON: res,
} }
}
return util.JSONResponse{
Code: 500,
JSON: jsonerror.Unknown("Failed to load avatar URL"),
}
} }
// SetAvatarURL implements PUT /profile/{userID}/avatar_url // SetAvatarURL implements PUT /profile/{userID}/avatar_url
@ -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,7 +134,10 @@ func GetDisplayName(
} }
} }
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 := displayName{ res := displayName{
DisplayName: profile.DisplayName, DisplayName: profile.DisplayName,
} }
@ -144,11 +145,6 @@ func GetDisplayName(
Code: 200, Code: 200,
JSON: res, JSON: res,
} }
}
return util.JSONResponse{
Code: 500,
JSON: jsonerror.Unknown("Failed to load display name"),
}
} }
// SetDisplayName implements PUT /profile/{userID}/displayname // SetDisplayName implements PUT /profile/{userID}/displayname