Explicitly ignore errors from writes to responses
Some checks failed
/ docker (push) Failing after 15m26s

This commit is contained in:
Melody Becker 2025-05-22 17:29:09 +02:00
parent ef95a0552d
commit 4a2462e24e
Signed by: mstar
SSH key fingerprint: SHA256:9VAo09aaVNTWKzPW7Hq2LW+ox9OdwmTSHRoD4mlz1yI
30 changed files with 280 additions and 237 deletions

View file

@ -63,7 +63,14 @@ func users(w http.ResponseWriter, r *http.Request) {
Preload(dbgen.User.BeingTypes).
First()
if err != nil {
webutils.ProblemDetails(w, 500, "/errors/db-failure", "internal database failure", nil, nil)
_ = webutils.ProblemDetails(
w,
500,
"/errors/db-failure",
"internal database failure",
nil,
nil,
)
if storage.HandleReconnectError(err) {
log.Warn().Msg("Connection to db lost. Reconnect attempt started")
} else {
@ -146,11 +153,11 @@ func users(w http.ResponseWriter, r *http.Request) {
encoded, err := json.Marshal(data)
if err != nil {
log.Error().Err(err).Msg("Failed to marshal response")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(encoded))
_, _ = fmt.Fprint(w, string(encoded))
}
func userFollowing(w http.ResponseWriter, r *http.Request) {
@ -160,11 +167,11 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
exists, err := dbgen.User.DoesUserWithIdExist(userId)
if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to check if user exists")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if !exists {
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
}
apUrl := activitypub.UserIdToApUrl(userId)
@ -172,7 +179,7 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
followingCount, err := dbgen.UserToUserRelation.CountFollowingForId(userId)
if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to get following count")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if pageNrStr == "" {
@ -186,13 +193,13 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(col)
if err != nil {
log.Error().Err(err).Any("raw", data).Msg("Failed to marshal following collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
} else {
pageNr, err := strconv.Atoi(pageNrStr)
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-page",
@ -207,12 +214,12 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
links, err := dbgen.UserToUserRelation.GetFollowingApLinksPagedForId(userId, pageNr)
switch err {
case gorm.ErrRecordNotFound:
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
log.Error().Err(err).Str("id", userId).Msg("Failed to get account via id")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
page := collectionPageOut{
@ -231,12 +238,12 @@ func userFollowing(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(page)
if err != nil {
log.Error().Err(err).Any("raw", page).Msg("Failed to marshal following collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
}
w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data))
_, _ = fmt.Fprint(w, string(data))
}
func userFollowers(w http.ResponseWriter, r *http.Request) {
@ -246,12 +253,12 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
exists, err := dbgen.User.DoesUserWithIdExist(userId)
if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to check if user exists")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if !exists {
log.Debug().Str("id", userId).Msg("user not found")
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
}
apUrl := activitypub.UserIdToApUrl(userId)
@ -259,7 +266,7 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
followersCount, err := dbgen.UserToUserRelation.CountFollowersForId(userId)
if err != nil {
log.Error().Err(err).Str("id", userId).Msg("Failed to get followers count")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
if pageNrStr == "" {
@ -273,13 +280,13 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(col)
if err != nil {
log.Error().Err(err).Any("raw", data).Msg("Failed to marshal followers collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
} else {
pageNr, err := strconv.Atoi(pageNrStr)
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-page",
@ -295,12 +302,12 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
switch err {
case gorm.ErrRecordNotFound:
log.Debug().Msg("No followers found")
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
return
case nil:
default:
log.Error().Err(err).Str("id", userId).Msg("Failed to get account via id")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
page := collectionPageOut{
@ -319,13 +326,13 @@ func userFollowers(w http.ResponseWriter, r *http.Request) {
data, err = json.Marshal(page)
if err != nil {
log.Error().Err(err).Any("raw", page).Msg("Failed to marshal followers collection page")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
}
log.Debug().Bytes("body", data).Msg("Sending collection(page) out")
w.Header().Add("Content-Type", "application/activity+json")
fmt.Fprint(w, string(data))
_, _ = fmt.Fprint(w, string(data))
}
/*
@ -354,7 +361,7 @@ var chain goap.BaseApChain = &goap.EmptyBaseObject{}
// data, err := goap.Compact(chain, baseLdContext)
if err != nil {
log.Error().Err(err).Msg("Failed to marshal ap chain")
webutils.ProblemDetailsStatusOnly(w, 500)
_ = webutils.ProblemDetailsStatusOnly(w, 500)
return
}
*/