mirror of
https://github.com/tucnak/telebot
synced 2024-11-05 06:00:58 +00:00
commit
fa41701896
@ -45,7 +45,7 @@ func NewAPIError(code int, msgs ...string) *APIError {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var errorRx = regexp.MustCompile(`{.+"error_code":(\d+),"description":"(.+)"}`)
|
var errorRx = regexp.MustCompile(`{.+"error_code":(\d+),"description":"(.+)".*}`)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// General errors
|
// General errors
|
||||||
|
18
util_test.go
Normal file
18
util_test.go
Normal file
@ -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…
Reference in New Issue
Block a user