Merge pull request #294 from aofei/v2

errors: fix regular expression
pull/300/head
demget 4 years ago committed by GitHub
commit fa41701896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -45,7 +45,7 @@ func NewAPIError(code int, msgs ...string) *APIError {
return err
}
var errorRx = regexp.MustCompile(`{.+"error_code":(\d+),"description":"(.+)"}`)
var errorRx = regexp.MustCompile(`{.+"error_code":(\d+),"description":"(.+)".*}`)
var (
// General errors

@ -0,0 +1,18 @@
package telebot
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestExtractOk(t *testing.T) {
data := []byte(`{"ok":true,"result":{"foo":"bar"}}`)
assert.NoError(t, extractOk(data))
data = []byte(`{"ok":false,"error_code":429,"description":"Too Many Requests: retry after 8","parameters":{"retry_after":8}}`)
assert.Error(t, extractOk(data))
data = []byte(`{"ok":false,"error_code":400,"description":"Bad Request: reply message not found"}`) // Also check the old format
assert.EqualError(t, extractOk(data), ErrToReplyNotFound.Error())
}
Loading…
Cancel
Save