Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add structured unknown error from telegram api #736

Open
wants to merge 2 commits into
base: v3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion bot_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ func extractOk(data []byte) error {
RetryAfter: int(retryAfter.(float64)),
}
default:
err = fmt.Errorf("telegram: %s (%d)", e.Description, e.Code)
err = &Error{
Code: e.Code,
Description: e.Description,
}
}

return err
Expand Down
9 changes: 9 additions & 0 deletions bot_raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ func TestExtractOk(t *testing.T) {
err: ErrGroupMigrated,
MigratedTo: -100123456789,
}, extractOk(data))

data = []byte(`{
"ok": false,
"error_code": 400,
"description": "Bad Request: can't parse entities: Can't find end tag corresponding to start tag \"b\""
}`)
assert.Equal(t, &Error{Code: 400, Description: `Bad Request: can't parse entities: Can't find end tag corresponding to start tag "b"`},
extractOk(data))

}

func TestExtractMessage(t *testing.T) {
Expand Down