fixed bug in /v2/send error parsing

This commit is contained in:
Bernhard B
2024-03-27 15:56:19 +01:00
parent a627d3e1ab
commit d083ba84e3
2 changed files with 12 additions and 12 deletions

View File

@@ -410,8 +410,18 @@ func (a *Api) SendV2(c *gin.Context) {
req.Number, req.Message, req.Recipients, req.Base64Attachments, req.Sticker,
req.Mentions, req.QuoteTimestamp, req.QuoteAuthor, req.QuoteMessage, req.QuoteMentions, req.TextMode, req.EditTimestamp)
if err != nil {
if data != nil {
c.JSON(400, SendMessageError{Msg: err.Error(), ChallengeTokens: (*data)[0].ChallengeTokens})
switch err.(type) {
case *client.RateLimitErrorType:
if rateLimitError, ok := err.(*client.RateLimitErrorType); ok {
extendedError := errors.New(err.Error() + ". Use the attached challenge tokens to lift the rate limit restrictions via the '/v1/accounts/{number}/rate-limit-challenge' endpoint.")
c.JSON(400, SendMessageError{Msg: extendedError.Error(), ChallengeTokens: rateLimitError.ChallengeTokens})
return
} else {
c.JSON(400, Error{Msg: err.Error()})
return
}
default:
c.JSON(400, Error{Msg: err.Error()})
return
}
c.JSON(400, Error{Msg: err.Error()})

View File

@@ -162,7 +162,6 @@ type SignalCliIdentityEntry struct {
type SendResponse struct {
Timestamp int64 `json:"timestamp"`
ChallengeTokens []string `json:"challenge_tokens"`
}
type About struct {
@@ -452,15 +451,6 @@ func (s *SignalClient) send(number string, message string,
rawData, err := jsonRpc2Client.getRaw("send", &number, request)
if err != nil {
cleanupAttachmentEntries(attachmentEntries)
switch errorType := err.(type) {
case *RateLimitErrorType:
rateLimitError := errors.New(err.Error() + ". Use the attached challenge tokens to lift the rate limit restrictions via the '/v1/accounts/{number}/rate-limit-challenge' endpoint.")
resp.ChallengeTokens = errorType.ChallengeTokens
return &resp, rateLimitError
default:
return nil, err
}
return nil, err
}