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

Global exception handler #22

Open
ArtemGet opened this issue Jan 22, 2025 · 3 comments
Open

Global exception handler #22

ArtemGet opened this issue Jan 22, 2025 · 3 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@ArtemGet
Copy link
Owner

For now we provide commands and sends that throws CmdException/SendException, but users dont have tool for global exception handling. I suggest adding such possibility. Class should take on target route and spare route as an attributes, similar to how CmdFork works.

@ArtemGet ArtemGet added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Jan 22, 2025
@yanmayak
Copy link

@ArtemGet I'll take this one

@yanmayak
Copy link

@ArtemGet should I restructure project (create exception directory with handler and SendException/CmdException classes)?
And I see an example in PeriodsBot.java. There is Oprional.empty() as spare route in handleExecution method. Is it general case or special case in handler? Should we log exception handling in general case?

@ArtemGet
Copy link
Owner Author

@yanmayak I think that exception handler is an entity related to '''bot''' configuration (we are planning that to be represented in teleroute), so it could be placed in '''bot''' dir.

The idea was to provide an interface to configure global exception handling, lets call it '''Emergency'''. It could be done via sending some default message to user/log or do any other custom logic. I see api usage as:
'''java
new MyBot(
new ERoute(
//spare routes if error thrown by default flow
),
//target routes aka app logic
)
'''

In future we could add chains of '''Emergency''' that wraps each other:

'''java
new MyBot(
new ELog(...),
new ELogKafka(...),
new EPg(...)
new ERoute(
//spare routes if error thrown by default flow
),
//target routes aka app logic
)
'''

I suggest that '''Emergency''' classes would have access to Update(or it's Wrap) and Cmd, that passed in method attributes, so it could execute command and send result quietly (without raising any exceptions), applying any custom logic that user wants if error appears. Lets implement '''ERoute''' that is mentioned in issue description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants