Skip to content

Commit

Permalink
provisioning/StartPM: use structured logging
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <[email protected]>
  • Loading branch information
sumnerevans committed Dec 30, 2023
1 parent 65c0e5a commit 1349c3f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,22 @@ func (prov *ProvisioningAPI) ResolveIdentifier(w http.ResponseWriter, r *http.Re
func (prov *ProvisioningAPI) StartPM(w http.ResponseWriter, r *http.Request) {
user := r.Context().Value("user").(*User)
phoneNum, _ := mux.Vars(r)["phonenum"]
prov.log.Debug().Msgf("StartPM from %v, phone number: %v", user.MXID, phoneNum)

log := prov.log.With().
Str("action", "start_pm").
Str("user_id", user.MXID.String()).
Str("phone_num", phoneNum).
Logger()
log.Debug().Msg("starting private message")

status, resp, err := prov.resolveIdentifier(user, phoneNum)
if err != nil {
errCode := "M_INTERNAL"
if status == http.StatusNotFound {
prov.log.Debug().Msgf("StartPM from %v, contact not found", user.MXID)
log.Debug().Msg("contact not found")
errCode = "M_NOT_FOUND"
} else {
prov.log.Err(err).Msgf("StartPM from %v, error looking up contact", user.MXID)
log.Err(err).Msg("error looking up contact")
}
jsonResponse(w, status, Error{
Success: false,
Expand All @@ -257,7 +263,7 @@ func (prov *ProvisioningAPI) StartPM(w http.ResponseWriter, r *http.Request) {
portal := user.GetPortalByChatID(resp.ChatID.UUID)
if portal.MXID == "" {
if err := portal.CreateMatrixRoom(user, nil); err != nil {
prov.log.Err(err).Msgf("StartPM from %v, error creating Matrix room", user.MXID)
log.Err(err).Msg("error looking up contact")
jsonResponse(w, http.StatusInternalServerError, Error{
Success: false,
Error: "Error creating Matrix room",
Expand Down

0 comments on commit 1349c3f

Please sign in to comment.