Skip to content

Commit

Permalink
Update error message if set-relay fails
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Dec 20, 2023
1 parent 2c1dfbe commit f4c0b12
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion imessage/ipc/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ var Err2FARequired = ipc.Error{
Message: "2-factor authentication required",
}

var ErrBadRegistrationCode = ipc.Error{
Code: "bad-registration-code",
Message: "Invalid registration code or provider not reachable",
}

func fnLogin(ctx context.Context, req ReqLogin) any {
im := global.IM
if req.Secondary {
Expand Down Expand Up @@ -1180,7 +1185,7 @@ func fnSetRelay(ctx context.Context, req ReqSetRelay) any {
versions, err := global.IM.FetchValidationVersions(ctx)
if err != nil {
zerolog.Ctx(ctx).Err(err).Msg("Failed to fetch versions from validation relay")
return fmt.Errorf("failed to get versions: %w", err)
return ErrBadRegistrationCode
}
if !global.InitialConfigureDone {
global.InitialConfigureDone = true
Expand Down
4 changes: 2 additions & 2 deletions provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ func (prov *ProvisioningAPI) SetRelay(w http.ResponseWriter, r *http.Request) {
Str("token", req.Token[:10]+"…").
Msg("Failed to fetch versions from relay")
jsonResponse(w, http.StatusBadRequest, &mautrix.RespError{
Err: "Failed to fetch versions from relay",
ErrCode: "COM.BEEPER.BAD_RELAY",
Err: "Invalid registration code or provider not reachable",
ErrCode: "COM.BEEPER.BAD_REGISTRATION_CODE",
})
return
}
Expand Down

0 comments on commit f4c0b12

Please sign in to comment.