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,7 +32,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
|
|||
var err error
|
||||
page, err = strconv.Atoi(pageStr)
|
||||
if err != nil {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-page",
|
||||
|
@ -43,7 +43,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
if page < 0 {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-page",
|
||||
|
@ -57,7 +57,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
|
|||
users, err := dbgen.User.GetPagedAllNonDeleted(uint(page))
|
||||
if err != nil {
|
||||
log.Error().Err(err).Int("page", page).Msg("Failed to get non-deleted users")
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusInternalServerError,
|
||||
"/errors/db-failure",
|
||||
|
@ -67,7 +67,7 @@ func getNonDeletedUsers(w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
return
|
||||
}
|
||||
webutils.SendJson(w, sliceutils.Map(users, func(t models.User) webshared.User {
|
||||
_ = webutils.SendJson(w, sliceutils.Map(users, func(t models.User) webshared.User {
|
||||
u := webshared.User{}
|
||||
u.FromModel(&t)
|
||||
return u
|
||||
|
@ -88,7 +88,7 @@ func createLocalUser(w http.ResponseWriter, r *http.Request) {
|
|||
data := Inbound{}
|
||||
err := jsonDecoder.Decode(&data)
|
||||
if err != nil {
|
||||
webutils.ProblemDetails(
|
||||
_ = webutils.ProblemDetails(
|
||||
w,
|
||||
http.StatusBadRequest,
|
||||
"/errors/bad-request-data",
|
||||
|
@ -111,20 +111,20 @@ func createLocalUser(w http.ResponseWriter, r *http.Request) {
|
|||
publicKeyEdBytes, privateKeyEdBytes, err := shared.GenerateKeypair(true)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to generate and marshal public key")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
publicKeyRsaBytes, privateKeyRsaBytes, err := shared.GenerateKeypair(false)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to generate and marshal public key")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
pkeyId := make([]byte, 64)
|
||||
_, err = rand.Read(pkeyId)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to generate passkey id")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -174,17 +174,17 @@ func createLocalUser(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
if err = query.Create(&user); err != nil {
|
||||
log.Error().Err(err).Msg("failed to create new local user")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
if err = storage.EnsureLocalUserIdHasLinks(user.ID); err != nil {
|
||||
log.Error().Err(err).Msg("Failed to add links to new user")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
}
|
||||
|
||||
func deleteUser(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.FormValue("id")
|
||||
dbgen.User.Where(dbgen.User.ID.Eq(id)).Delete()
|
||||
_, _ = dbgen.User.Where(dbgen.User.ID.Eq(id)).Delete()
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
|
@ -212,7 +212,7 @@ func returnKeypair(w http.ResponseWriter, r *http.Request) {
|
|||
if err != nil {
|
||||
hlog.FromRequest(r).Error().Err(err).Msg("Pem Sanity check failed")
|
||||
}
|
||||
fmt.Fprintf(w, "%s\n\n%s", privKeyPem, pubKeyPen)
|
||||
_, _ = fmt.Fprintf(w, "%s\n\n%s", privKeyPem, pubKeyPen)
|
||||
}
|
||||
|
||||
func issueUserImport(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -235,20 +235,20 @@ func proxyMessageToTarget(w http.ResponseWriter, r *http.Request) {
|
|||
err := dec.Decode(&data)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to decode json body")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
log.Debug().Any("data", data).Msg("Received message")
|
||||
user, err := dbgen.User.GetByUsername(data.From)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get user from storage")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
targetId, err := activitypub.ImportRemoteAccountByHandle(data.Target)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to import target user")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
target, err := dbgen.User.Where(dbgen.User.ID.Eq(targetId)).
|
||||
|
@ -256,14 +256,14 @@ func proxyMessageToTarget(w http.ResponseWriter, r *http.Request) {
|
|||
First()
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to get target user from db")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
outBody, err := json.Marshal(data.Message)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Failed to marshal out data")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
log.Debug().Bytes("request-body", outBody).Msg("Body of proxied request")
|
||||
|
@ -275,10 +275,10 @@ func proxyMessageToTarget(w http.ResponseWriter, r *http.Request) {
|
|||
)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("Request failed")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
defer response.Body.Close()
|
||||
defer func() { _ = response.Body.Close() }()
|
||||
respBody, _ := io.ReadAll(response.Body)
|
||||
log.Debug().
|
||||
Int("status-code", response.StatusCode).
|
||||
|
@ -291,9 +291,12 @@ func kickoffFollow(w http.ResponseWriter, r *http.Request) {
|
|||
From string `json:"from"`
|
||||
To string `json:"to"`
|
||||
}
|
||||
log := hlog.FromRequest(r)
|
||||
var data Inbound
|
||||
dec := json.NewDecoder(r.Body)
|
||||
dec.Decode(&data)
|
||||
_ = dec.Decode(&data)
|
||||
log.Error().Msg("Not implemented yet")
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
}
|
||||
|
||||
func requestAs(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -307,24 +310,24 @@ func requestAs(w http.ResponseWriter, r *http.Request) {
|
|||
err := dec.Decode(&data)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Failed to decode json body")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
user, err := dbgen.User.GetByUsername(data.Username)
|
||||
if err != nil {
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
res, _, err := webshared.RequestSigned("GET", data.TargetUrl, nil, user)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Request failed")
|
||||
webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
if res.StatusCode != 200 {
|
||||
webutils.ProblemDetailsStatusOnly(w, res.StatusCode)
|
||||
_ = webutils.ProblemDetailsStatusOnly(w, res.StatusCode)
|
||||
return
|
||||
}
|
||||
body, _ := io.ReadAll(res.Body)
|
||||
fmt.Fprint(w, string(body))
|
||||
_, _ = fmt.Fprint(w, string(body))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue