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

@ -31,7 +31,7 @@ func postAs(w http.ResponseWriter, r *http.Request) {
data := Inbound{}
err := dec.Decode(&data)
if err != nil {
webutils.ProblemDetails(
_ = webutils.ProblemDetails(
w,
http.StatusBadRequest,
"/errors/bad-request-data",
@ -49,10 +49,10 @@ func postAs(w http.ResponseWriter, r *http.Request) {
user, err := dbgen.User.GetByUsername(data.Username)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
} else {
log.Error().Err(err).Str("name", data.Username).Msg("Failed to find user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
}
return
}
@ -88,7 +88,7 @@ func postAs(w http.ResponseWriter, r *http.Request) {
Str("username", data.Username).
Str("content", data.Content).
Msg("Failed to create message")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
activity := models.Activity{
@ -105,28 +105,28 @@ func postAs(w http.ResponseWriter, r *http.Request) {
err = tx.Commit()
if err != nil {
log.Error().Err(err).Msg("Failed to commit note creation")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
u2u := dbgen.UserToUserRelation
links, err := u2u.GetFollowerInboxesForId(user.ID)
if err != nil {
log.Error().Err(err).Msg("Failed to get follower inbox links for user")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
log.Debug().Strs("links", links).Send()
act, err := webap.CreateFromStorage(r.Context(), activity.Id)
if err != nil {
log.Error().Err(err).Msg("Failed to fetch and format new note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
act.Context = activitypub.BaseLdContext
outData, err := json.Marshal(act)
if err != nil {
log.Error().Err(err).Msg("Failed to marshal new note")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
for _, link := range links {
@ -151,13 +151,13 @@ func notesFrom(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Error().Err(err).Str("name", username).Msg("Failed to get user")
storage.HandleReconnectError(err)
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
notes, err := dbgen.Note.GetNotesPaged(user.ID, 0, uint8(models.NOTE_TARGET_PUBLIC))
if err != nil {
log.Error().Err(err).Str("name", username).Msg("Failed to get notes")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
publicNotes := sliceutils.Map(notes, func(t models.Note) webshared.Note {
@ -165,7 +165,7 @@ func notesFrom(w http.ResponseWriter, r *http.Request) {
n.FromModel(&t)
return n
})
webutils.SendJson(w, publicNotes)
_ = webutils.SendJson(w, publicNotes)
}
func inReplyTo(w http.ResponseWriter, r *http.Request) {
@ -176,7 +176,7 @@ func inReplyTo(w http.ResponseWriter, r *http.Request) {
Find()
if err != nil {
log.Error().Err(err).Str("id", noteId).Msg("Error getting replies to note with id")
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
return
}
_ = webutils.SendJson(w, notes)