Skip to content

Commit

Permalink
signalmeow/web: log attachment download http status
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 14, 2024
1 parent 7688e74 commit 11686cb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/signalmeow/attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"crypto/cipher"
"crypto/hmac"
"crypto/sha256"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -72,6 +73,14 @@ func DownloadAttachment(ctx context.Context, a *signalpb.AttachmentPointer) ([]b
if err != nil {
return nil, err
}
if resp.StatusCode > 400 {
if json.Valid(body) && len(body) < 4096 {
zerolog.Ctx(ctx).Debug().RawJSON("response_data", body).Msg("Failed download response json")
} else if len(body) < 1024 {
zerolog.Ctx(ctx).Debug().Bytes("response_data", body).Msg("Failed download response data")
}
return nil, fmt.Errorf("unexpected status code %d", resp.StatusCode)
}

return decryptAttachment(body, a.Key, a.Digest, *a.Size)
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/signalmeow/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ func GetAttachment(ctx context.Context, path string, cdnNumber uint32, opt *HTTP
if err != nil {
return nil, err
}
log.Debug().Msg("Received Attachment HTTP response")
log.Debug().
Int("status_code", resp.StatusCode).
Int64("content_length", resp.ContentLength).
Msg("Received Attachment HTTP response")

return resp, err
}

0 comments on commit 11686cb

Please sign in to comment.