Skip to content

Commit

Permalink
provisioning/ResolveIdentifier: 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 2a22f56 commit 65c0e5a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,13 @@ func (prov *ProvisioningAPI) resolveIdentifier(user *User, phoneNum string) (int
phoneNum = "+" + phoneNum
}
if user.SignalDevice == nil {
prov.log.Debug().Msgf("ResolveIdentifier from %v, no device found", user.MXID)
return http.StatusUnauthorized, nil, fmt.Errorf("Not currently connected to Signal")
}
contact, err := user.SignalDevice.ContactByE164(phoneNum)
if err != nil {
prov.log.Err(err).Msgf("ResolveIdentifier from %v, error looking up contact", user.MXID)
return http.StatusInternalServerError, nil, fmt.Errorf("Error looking up number in local contact list: %w", err)
}
if contact == nil {
prov.log.Debug().Msgf("ResolveIdentifier from %v, contact not found", user.MXID)
return http.StatusNotFound, nil, fmt.Errorf("The bridge does not have the Signal ID for the number %s", phoneNum)
}

Expand All @@ -204,16 +201,22 @@ func (prov *ProvisioningAPI) resolveIdentifier(user *User, phoneNum string) (int
func (prov *ProvisioningAPI) ResolveIdentifier(w http.ResponseWriter, r *http.Request) {
user := r.Context().Value("user").(*User)
phoneNum, _ := mux.Vars(r)["phonenum"]
prov.log.Debug().Msgf("ResolveIdentifier from %v, phone number: %v", user.MXID, phoneNum)

log := prov.log.With().
Str("action", "resolve_identifier").
Str("user_id", user.MXID.String()).
Str("phone_num", phoneNum).
Logger()
log.Debug().Msg("resolving identifier")

status, resp, err := prov.resolveIdentifier(user, phoneNum)
if err != nil {
errCode := "M_INTERNAL"
if status == http.StatusNotFound {
prov.log.Debug().Msgf("ResolveIdentifier from %v, contact not found", user.MXID)
log.Debug().Msg("contact not found")
errCode = "M_NOT_FOUND"
} else {
prov.log.Err(err).Msgf("ResolveIdentifier from %v, error looking up contact", user.MXID)
log.Err(err).Msg("error looking up contact")
}
jsonResponse(w, status, Error{
Success: false,
Expand Down

0 comments on commit 65c0e5a

Please sign in to comment.