diff --git a/pkg/signalmeow/attachments.go b/pkg/signalmeow/attachments.go index 64054dd8..c0859b7e 100644 --- a/pkg/signalmeow/attachments.go +++ b/pkg/signalmeow/attachments.go @@ -23,6 +23,7 @@ import ( "crypto/cipher" "crypto/hmac" "crypto/sha256" + "encoding/json" "errors" "fmt" "io" @@ -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) } diff --git a/pkg/signalmeow/web/web.go b/pkg/signalmeow/web/web.go index 7bcc0352..11191284 100644 --- a/pkg/signalmeow/web/web.go +++ b/pkg/signalmeow/web/web.go @@ -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 }