Skip to content

Commit

Permalink
Improve error responses when the provider can't be reached when regis…
Browse files Browse the repository at this point in the history
…tering from provisioning APIs
  • Loading branch information
bradtgmurray committed Jan 10, 2024
1 parent 722246d commit e57ee20
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,18 @@ func (prov *ProvisioningAPI) Reregister(w http.ResponseWriter, r *http.Request)
err := user.IM.RegisterIDS(r.Context(), force)
if err != nil {
log.Err(err).Msg("Failed to reregister IDS")
jsonResponse(w, http.StatusInternalServerError, &mautrix.RespError{
ErrCode: "M_UNKNOWN",
Err: "Internal error",
})

if errors.Is(err, nacserv.ErrProviderNotReachable) {
jsonResponse(w, http.StatusBadRequest, &mautrix.RespError{
Err: "Invalid registration code or provider not reachable",
ErrCode: "COM.BEEPER.BAD_REGISTRATION_CODE",
})
} else {
jsonResponse(w, http.StatusInternalServerError, &mautrix.RespError{
ErrCode: "M_UNKNOWN",
Err: "Internal error",
})
}
return
}
if req.ClearIDSCache {
Expand Down Expand Up @@ -436,10 +444,18 @@ func (prov *ProvisioningAPI) SetRelay(w http.ResponseWriter, r *http.Request) {
err := user.IM.RegisterIDS(r.Context(), true)
if err != nil {
log.Err(err).Msg("Failed to reregister IDS")
jsonResponse(w, http.StatusInternalServerError, &mautrix.RespError{
ErrCode: "M_UNKNOWN",
Err: "Internal error",
})

if errors.Is(err, nacserv.ErrProviderNotReachable) {
jsonResponse(w, http.StatusBadRequest, &mautrix.RespError{
Err: "Invalid registration code or provider not reachable",
ErrCode: "COM.BEEPER.BAD_REGISTRATION_CODE",
})
} else {
jsonResponse(w, http.StatusInternalServerError, &mautrix.RespError{
ErrCode: "M_UNKNOWN",
Err: "Internal error",
})
}
return
}
}
Expand Down

0 comments on commit e57ee20

Please sign in to comment.