Compare commits

..

1 Commits

3 changed files with 6 additions and 28 deletions

View File

@ -324,14 +324,8 @@ func (a *Api) RegisterNumber(c *gin.Context) {
err = a.signalClient.RegisterNumber(number, req.UseVoice, req.Captcha)
if err != nil {
switch err.(type) {
case *client.InvalidTransportError:
c.JSON(400, Error{Msg: "Couldn't use SMS verification to register the specified number. Wait 60 seconds and try again with {\"use_voice\": true}"})
return
default:
c.JSON(400, Error{Msg: err.Error()})
return
}
c.JSON(400, gin.H{"error": err.Error()})
return
}
c.Writer.WriteHeader(201)
}

View File

@ -749,8 +749,6 @@ func (s *SignalClient) About() About {
}
func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha string) error {
var err error
var jsonRpc2Client *JsonRpc2Client
if s.signalCliMode == JsonRpc {
type Request struct {
UseVoice bool `json:"voice,omitempty"`
@ -767,11 +765,12 @@ func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha stri
request.Captcha = captcha
}
jsonRpc2Client, err = s.getJsonRpc2Client()
jsonRpc2Client, err := s.getJsonRpc2Client()
if err != nil {
return err
}
_, err = jsonRpc2Client.getRaw("register", nil, request)
return err
} else {
command := []string{"--config", s.signalCliConfig, "-a", number, "register"}
@ -783,16 +782,9 @@ func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha stri
command = append(command, []string{"--captcha", captcha}...)
}
_, err = s.cliClient.Execute(true, command, "")
_, err := s.cliClient.Execute(true, command, "")
return err
}
if err != nil {
if !useVoice && strings.Contains(err.Error(), "StatusCode: 400 (InvalidTransportModeException)") {
return &InvalidTransportError{Description: "Couldn't use SMS verification to register number."}
}
}
return err
}
func (s *SignalClient) UnregisterNumber(number string, deleteAccount bool, deleteLocalData bool) error {

View File

@ -23,11 +23,3 @@ type InternalError struct {
func (e *InternalError) Error() string {
return e.Description
}
type InvalidTransportError struct {
Description string
}
func (e *InvalidTransportError) Error() string {
return e.Description
}