Explicitly ignore errors from writes to responses
Some checks failed
/ docker (push) Failing after 15m26s
Some checks failed
/ docker (push) Failing after 15m26s
This commit is contained in:
parent
ef95a0552d
commit
4a2462e24e
30 changed files with 280 additions and 237 deletions
|
@ -32,24 +32,24 @@ func activityAccept(w http.ResponseWriter, r *http.Request) {
|
|||
activity, err := CreateFromStorage(r.Context(), id)
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
case nil:
|
||||
activity.Context = activitypub.BaseLdContext
|
||||
data, err := json.Marshal(activity)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity")
|
||||
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))
|
||||
default:
|
||||
if storage.HandleReconnectError(err) {
|
||||
log.Error().Err(err).Msg("Connection failed, restart attempt started")
|
||||
} else {
|
||||
log.Error().Err(err).Msg("Failed to get create activity from db")
|
||||
}
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,24 +31,24 @@ func activityCreate(w http.ResponseWriter, r *http.Request) {
|
|||
activity, err := CreateFromStorage(r.Context(), id)
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
case nil:
|
||||
activity.Context = activitypub.BaseLdContext
|
||||
data, err := json.Marshal(activity)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity")
|
||||
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))
|
||||
default:
|
||||
if storage.HandleReconnectError(err) {
|
||||
log.Error().Err(err).Msg("Connection failed, restart attempt started")
|
||||
} else {
|
||||
log.Error().Err(err).Msg("Failed to get create activity from db")
|
||||
}
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,24 +31,24 @@ func activityFollow(w http.ResponseWriter, r *http.Request) {
|
|||
activity, err := FollowFromStorage(r.Context(), id)
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
case nil:
|
||||
activity.Context = activitypub.BaseLdContext
|
||||
data, err := json.Marshal(activity)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Any("activity", activity).Msg("Failed to marshal create activity")
|
||||
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))
|
||||
default:
|
||||
if storage.HandleReconnectError(err) {
|
||||
log.Error().Err(err).Msg("Connection failed, restart attempt started")
|
||||
} else {
|
||||
log.Error().Err(err).Msg("Failed to get create activity from db")
|
||||
}
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
|
|||
data := map[string]any{}
|
||||
err = json.Unmarshal(body, &data)
|
||||
if err != nil {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -53,7 +53,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
if _, ok := data["@context"]; !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -65,7 +65,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
objectType, ok := data["type"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -77,7 +77,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
_, ok = data["id"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -104,7 +104,7 @@ func userInbox(w http.ResponseWriter, r *http.Request) {
|
|||
handleCreate(w, r, data)
|
||||
default:
|
||||
log.Warn().Str("object-type", objectType).Msg("Unknown message type")
|
||||
webutils.ProblemDetailsStatusOnly(w, 500)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, 500)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,7 +113,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
activityId := object["id"].(string)
|
||||
likerUrl, ok := object["actor"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -126,7 +126,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
// TODO: Account for case where object is embedded in like
|
||||
targetUrl, ok := object["object"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -142,7 +142,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
Strs("match-results", targetIdMatches).
|
||||
Str("url", targetUrl).
|
||||
Msg("Url didn't match id extractor regex")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
targetId := targetIdMatches[1]
|
||||
|
@ -152,7 +152,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
switch err {
|
||||
case nil:
|
||||
case gorm.ErrRecordNotFound:
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -163,7 +163,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
return
|
||||
default:
|
||||
log.Error().Err(err).Str("note-id", targetId).Msg("Failed to get note from db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// Import liker after verifying that target note is correct
|
||||
|
@ -173,7 +173,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
Err(err).
|
||||
Str("liker-url", likerUrl).
|
||||
Msg("Failed to import liking remote account")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
reaction := models.Reaction{
|
||||
|
@ -190,7 +190,7 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
log.Error().Err(err).Any("raw-reaction", reaction).Msg("Failed to store reaction in db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
// TODO: Create corresponding activity too
|
||||
activity := models.Activity{
|
||||
|
@ -203,12 +203,12 @@ func handleLike(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
log.Error().Err(err).Any("raw-reaction", reaction).Msg("Failed to store reaction in db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to commit reaction transaction to db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -217,7 +217,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
log.Debug().Msg("Received follow request")
|
||||
objectId, ok := object["id"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -229,7 +229,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
}
|
||||
actorApId, ok := object["actor"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -241,7 +241,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
}
|
||||
targetUrl, ok := object["object"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -253,7 +253,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
}
|
||||
followedMatch := objectIdRegex.FindStringSubmatch(targetUrl)
|
||||
if len(followedMatch) != 2 {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -267,18 +267,18 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
followed, err := dbgen.User.Where(dbgen.User.ID.Eq(followedId)).First()
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
return
|
||||
case nil:
|
||||
default:
|
||||
log.Error().Err(err).Str("target-id", followedId).Msg("Failed to get account from db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
follower, err := activitypub.ImportRemoteAccountByAPUrl(actorApId)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to import following account")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
u2u := dbgen.UserToUserRelation
|
||||
|
@ -296,7 +296,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Str("follower", follower.ID).
|
||||
Str("followed", followedId).
|
||||
Msg("Failed to count follow relations")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if followRelations > 0 {
|
||||
|
@ -312,7 +312,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
log.Error().Err(err).Any("follow-request", req).Msg("Failed to store follow request")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
activity := models.Activity{
|
||||
|
@ -325,13 +325,13 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
log.Error().Err(err).Any("activity", activity).Msg("Failed to store follow activity")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to commit follow activity transaction")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if !followed.RestrictedFollow {
|
||||
|
@ -340,7 +340,7 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
log.Error().Err(err).Msg("Failed to update follow to confirmed")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
acceptActivity := models.Activity{
|
||||
|
@ -353,13 +353,13 @@ func handleFollow(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
log.Error().Err(err).Msg("Failed to store accept activity in db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to commit follow accept to db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
|
@ -402,7 +402,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
log := hlog.FromRequest(r)
|
||||
rawTarget, ok := object["object"]
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -422,7 +422,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
objType, ok := target["type"].(string)
|
||||
// TODO: Ensure accept is only used for follows
|
||||
if !ok || objType != "Follow" {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -434,7 +434,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
}
|
||||
targetObjectId, ok = target["id"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -445,7 +445,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
return
|
||||
}
|
||||
default:
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -457,7 +457,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
}
|
||||
internalIdMatch := objectIdRegex.FindStringSubmatch(targetObjectId)
|
||||
if len(internalIdMatch) != 2 {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -471,7 +471,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
followActivity, err := dbgen.Activity.Where(dbgen.Activity.Id.Eq(internalId)).First()
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
return
|
||||
case nil:
|
||||
default:
|
||||
|
@ -479,7 +479,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Err(err).
|
||||
Str("target-id", internalId).
|
||||
Msg("Failed to get target follow activity from db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
relationId := other.Must(strconv.ParseUint(followActivity.ObjectId, 10, 64))
|
||||
|
@ -490,7 +490,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
// No need to rollback, nothing was done
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
return
|
||||
case nil:
|
||||
default:
|
||||
|
@ -499,7 +499,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Err(err).
|
||||
Str("target-id", internalId).
|
||||
Msg("Failed to update follow status to confirmed follow")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
activity := models.Activity{
|
||||
|
@ -515,7 +515,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Err(err).
|
||||
Str("target-id", internalId).
|
||||
Msg("Failed to store accept activity in db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = tx.Commit()
|
||||
|
@ -524,7 +524,7 @@ func handleAccept(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Err(err).
|
||||
Str("target-id", internalId).
|
||||
Msg("Failed to commit accept transaction")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -534,7 +534,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
log := hlog.FromRequest(r)
|
||||
rawTarget, ok := object["object"]
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -554,7 +554,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
objType, ok := target["type"].(string)
|
||||
// TODO: Ensure accept is only used for follows
|
||||
if !ok || objType != "Follow" {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -566,7 +566,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
}
|
||||
targetObjectId, ok = target["id"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -577,7 +577,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
return
|
||||
}
|
||||
default:
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -589,7 +589,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
}
|
||||
internalIdMatch := objectIdRegex.FindStringSubmatch(targetObjectId)
|
||||
if len(internalIdMatch) != 2 {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -603,7 +603,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
followActivity, err := dbgen.Activity.Where(dbgen.Activity.Id.Eq(internalId)).First()
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
return
|
||||
case nil:
|
||||
default:
|
||||
|
@ -611,7 +611,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Err(err).
|
||||
Str("target-id", internalId).
|
||||
Msg("Failed to get target follow activity from db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
relationId := other.Must(strconv.ParseUint(followActivity.ObjectId, 10, 64))
|
||||
|
@ -621,7 +621,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
// No need to rollback, nothing was done
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
return
|
||||
case nil:
|
||||
default:
|
||||
|
@ -630,7 +630,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Err(err).
|
||||
Str("target-id", internalId).
|
||||
Msg("Failed to delete follow status")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_, err = tx.Activity.Where(
|
||||
|
@ -641,7 +641,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
log.Error().Err(err).Msg("Failed to delete accept for later rejected follow")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
activity := models.Activity{
|
||||
|
@ -657,7 +657,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Err(err).
|
||||
Str("target-id", internalId).
|
||||
Msg("Failed to store accept activity in db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = tx.Commit()
|
||||
|
@ -666,7 +666,7 @@ func handleReject(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Err(err).
|
||||
Str("target-id", internalId).
|
||||
Msg("Failed to commit accept transaction")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -680,7 +680,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Err(err).
|
||||
Any("raw", object).
|
||||
Msg("Failed to marshal create activity to proper type")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
actingUser, err := activitypub.ImportRemoteAccountByAPUrl(activity.Actor)
|
||||
|
@ -689,7 +689,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Err(err).
|
||||
Str("actor", activity.Actor).
|
||||
Msg("Failed to import remote actor for note")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
switch val := activity.Object.(type) {
|
||||
|
@ -697,18 +697,18 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
actor, err := dbgen.User.GetById(r.PathValue("id"))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get local actor for importing targeted note")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_, err = activitypub.ImportRemoteNote(val, actor)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Str("note-url", val).Msg("Failed to import remote note that landed as id in the inbox")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
case map[string]any:
|
||||
default:
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -733,11 +733,11 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
Err(err).
|
||||
Any("raw", activity.Object).
|
||||
Msg("Failed to unmarshal create object into note")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if objectNote.Type != "Note" {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -774,7 +774,7 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
log.Error().Err(err).Any("note", dbNote).Msg("Failed to create note in db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
createActivity := models.Activity{
|
||||
|
@ -787,13 +787,13 @@ func handleCreate(w http.ResponseWriter, r *http.Request, object map[string]any)
|
|||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
log.Error().Err(err).Any("note", dbNote).Msg("Failed to create note create activity in db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Any("note", dbNote).Msg("Failed to submit note creation in db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
_ = object["id"].(string)
|
||||
_, ok := object["actor"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -29,7 +29,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
}
|
||||
rawTarget, ok := object["object"]
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -49,7 +49,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
case map[string]any:
|
||||
objType, ok := target["type"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -62,7 +62,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
targetObjectType = objType
|
||||
targetObjectId, ok = target["id"].(string)
|
||||
if !ok {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -73,7 +73,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
return
|
||||
}
|
||||
default:
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -92,7 +92,7 @@ func handleUndo(w http.ResponseWriter, r *http.Request, object map[string]any) {
|
|||
log.Error().
|
||||
Str("undo-target-type", targetObjectType).
|
||||
Msg("Unknown/unimplemented undo target type")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,7 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
|
|||
Err(err).
|
||||
Str("activity-id", targetId).
|
||||
Msg("Error while looking for like activity")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
reactionId := uint(other.Must(strconv.ParseUint(act.ObjectId, 10, 64)))
|
||||
|
@ -123,7 +123,7 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
|
|||
Err(err).
|
||||
Str("activity-id", targetId).
|
||||
Msg("Error while looking for find activity")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
tx := dbgen.Q.Begin()
|
||||
|
@ -131,7 +131,7 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
|
|||
if err != nil {
|
||||
_ = tx.Rollback()
|
||||
log.Error().Err(err).Str("activity-id", act.Id).Msg("Failed to delete activity on undo")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_, err = tx.Reaction.Where(dbgen.Reaction.ID.Eq(reaction.ID)).Delete()
|
||||
|
@ -141,13 +141,13 @@ func undoLike(w http.ResponseWriter, r *http.Request, object map[string]any, tar
|
|||
Err(err).
|
||||
Uint("reaction-id", reaction.ID).
|
||||
Msg("Failed to delete reaction on undo")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to delete reaction and activity")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
|
|||
Err(err).
|
||||
Str("activity-id", targetId).
|
||||
Msg("Error while looking for follow activity")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
relationId := other.Must(strconv.ParseUint(act.ObjectId, 10, 64))
|
||||
|
@ -176,7 +176,7 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
|
|||
Err(err).
|
||||
Str("activity-id", act.Id).
|
||||
Msg("Failed to delete follow activity on undo")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
// Delete all activities that reference the follow activity (so accept/reject if exists)
|
||||
|
@ -187,7 +187,7 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
|
|||
Err(err).
|
||||
Str("activity-id", act.Id).
|
||||
Msg("Failed to delete accept/reject activity for follow on undo")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
_, err = tx.UserToUserRelation.Where(dbgen.UserToUserRelation.ID.Eq(relationId)).Delete()
|
||||
|
@ -198,12 +198,12 @@ func undoFollow(w http.ResponseWriter, r *http.Request, object map[string]any, t
|
|||
Str("activity-id", act.Id).
|
||||
Uint64("relation-id", relationId).
|
||||
Msg("Failed to delete user-to-user relation for follow on undo")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to delete reaction and activity")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,25 +51,25 @@ func objectNote(w http.ResponseWriter, r *http.Request) {
|
|||
note, err := NoteFromStorage(r.Context(), id)
|
||||
switch err {
|
||||
case gorm.ErrRecordNotFound:
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
return
|
||||
case nil:
|
||||
note.Context = activitypub.BaseLdContext
|
||||
data, err := json.Marshal(note)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Any("activity", note).Msg("Failed to marshal create activity")
|
||||
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))
|
||||
default:
|
||||
if storage.HandleReconnectError(err) {
|
||||
log.Error().Err(err).Msg("Connection failed, restart attempt started")
|
||||
} else {
|
||||
log.Error().Err(err).Msg("Failed to get create activity from db")
|
||||
}
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -27,7 +27,7 @@ func BuildApiRouter() http.Handler {
|
|||
),
|
||||
)
|
||||
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "in api")
|
||||
_, _ = fmt.Fprint(w, "in api")
|
||||
})
|
||||
return router
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ func WellKnownWebfinger(w http.ResponseWriter, r *http.Request) {
|
|||
requestedResource := r.FormValue("resource")
|
||||
matches := webfingerResourceRegex.FindStringSubmatch(requestedResource)
|
||||
if len(matches) == 0 {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/webfinger-bad-resource",
|
||||
|
@ -56,16 +56,16 @@ func WellKnownWebfinger(w http.ResponseWriter, r *http.Request) {
|
|||
// Fail if requested user is a different domain
|
||||
// TODO: Decide whether to include the info that it's a different domain
|
||||
if domain != config.GlobalConfig.General.GetFullDomain() {
|
||||
webutils.ProblemDetailsStatusOnly(w, 404)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, 404)
|
||||
return
|
||||
}
|
||||
user, err := dbgen.User.GetByUsername(username)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
webutils.ProblemDetailsStatusOnly(w, 404)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, 404)
|
||||
} else {
|
||||
// Fail the request, then attempt to reconnect
|
||||
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 {
|
||||
|
@ -101,7 +101,7 @@ func WellKnownWebfinger(w http.ResponseWriter, r *http.Request) {
|
|||
},
|
||||
},
|
||||
}
|
||||
webutils.SendJson(w, &data)
|
||||
_ = webutils.SendJson(w, &data)
|
||||
}
|
||||
|
||||
func NodeInfoOverview(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -117,7 +117,7 @@ func NodeInfoOverview(w http.ResponseWriter, r *http.Request) {
|
|||
},
|
||||
},
|
||||
}
|
||||
webutils.SendJson(w, data)
|
||||
_ = webutils.SendJson(w, data)
|
||||
}
|
||||
|
||||
func NodeInfo21(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -125,7 +125,14 @@ func NodeInfo21(w http.ResponseWriter, r *http.Request) {
|
|||
log := hlog.FromRequest(r)
|
||||
userCount, err := u.Where(u.DeletedAt.IsNull(), u.Verified.Is(true), u.ServerId.Eq(1)).Count()
|
||||
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 {
|
||||
|
@ -136,7 +143,14 @@ func NodeInfo21(w http.ResponseWriter, r *http.Request) {
|
|||
n := dbgen.Note
|
||||
noteCount, err := n.Where(n.DeletedAt.IsNull(), n.OriginId.Eq(1)).Count()
|
||||
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 {
|
||||
|
@ -169,7 +183,7 @@ func NodeInfo21(w http.ResponseWriter, r *http.Request) {
|
|||
LocalComments: 0},
|
||||
Metadata: map[string]any{},
|
||||
}
|
||||
webutils.SendJson(w, data)
|
||||
_ = webutils.SendJson(w, data)
|
||||
}
|
||||
|
||||
func NodeInfo20(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -177,7 +191,14 @@ func NodeInfo20(w http.ResponseWriter, r *http.Request) {
|
|||
log := hlog.FromRequest(r)
|
||||
userCount, err := u.Where(u.DeletedAt.IsNull(), u.Verified.Is(true)).Count()
|
||||
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 {
|
||||
|
@ -188,7 +209,14 @@ func NodeInfo20(w http.ResponseWriter, r *http.Request) {
|
|||
n := dbgen.Note
|
||||
noteCount, err := n.Where(n.DeletedAt.IsNull(), n.OriginId.Eq(1)).Count()
|
||||
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 {
|
||||
|
@ -221,5 +249,5 @@ func NodeInfo20(w http.ResponseWriter, r *http.Request) {
|
|||
Metadata: map[string]any{},
|
||||
}
|
||||
|
||||
webutils.SendJson(w, data)
|
||||
_ = webutils.SendJson(w, data)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue