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

Conversation

ev-gusev
Copy link

There are cases when api telegram returns errors that do not have static text, for example:

Bad Request: can't parse entities: Can't find end tag corresponding to start tag "b"

In this case, it is impossible to determine on the library user side that this error is a Bad Request, as it will be generic and will only contain the error text

This PR solves this problem and allows to handle such errors as follows:

	var e *telebot.Error
	if errors.As(err, &e) {
		if e.Code == 400 {
			...
		}
	}

Errors that were previously predefined as bad request will be handled in the same form

@demget
Copy link
Collaborator

demget commented Aug 29, 2024

Hey @ev-gusev, good catch. I think we can change default case instead to generalize such conversion

@ev-gusev
Copy link
Author

ev-gusev commented Aug 29, 2024

Hey @ev-gusev, good catch. I think we can change default case instead to generalize such conversion

I actually thought about it, but I thought that there might be library users who used regular expressions and parsed these errors that were not of type Error to accomplish the goals I was pursuing . So I didn't risk it

@ev-gusev
Copy link
Author

@demget What do you think about it?

@demget demget added this to the V4 milestone Sep 23, 2024
@demget
Copy link
Collaborator

demget commented Sep 23, 2024

@ev-gusev we will include this in the breaking V4 release

@ev-gusev
Copy link
Author

@ev-gusev we will include this in the breaking V4 release

I got you, changed the default case

@ev-gusev ev-gusev changed the title Add structured Bad Request error Add structured unknown error from telegram api Oct 5, 2024
@ev-gusev
Copy link
Author

@demget Is something wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants