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 on_error handler #35

Merged
merged 1 commit into from
Dec 23, 2024
Merged

Add on_error handler #35

merged 1 commit into from
Dec 23, 2024

Conversation

towhans
Copy link
Contributor

@towhans towhans commented Sep 16, 2024

This allows handling cases when Hammer Backend returns {:error, ...} tuple. For example Hammer.Backend.Redis can return {:error, %Redix.ConnectionError{}} which is not technically an over limit return value but more of a Internal Server Error response.

This will allow to return 500 https status code in case Hammer.Backend returns an {:error, _} which is now impossible because the on_deny handler is called both for :deny and :error The new optional handler can handle error case.

@ruslandoga
Copy link

ruslandoga commented Nov 14, 2024

👋 @towhans

Wouldn't it be easier if status=500 is returned by default on all errors?

I'm working on a new API for Hammer ExHammer/hammer#104 and right now I think the backends would only return allow or deny, and all backend errors would be exceptions.

@towhans
Copy link
Contributor Author

towhans commented Nov 14, 2024

Currently if Hammer.Backend.Redis returns {:error, %Redix.ConnectionError{}} then Hammer itself returns deny. Not an error. It's covering that error up. Raising exceptions would also be a good way to surface the error 👍

@epinault
Copy link
Contributor

epinault commented Dec 20, 2024

if you can rebase I will merge this . Just know this library will then be also EOL anyway soon enough .I am working on the 7x. final release candidate soon and that lib will not longer be useful

# Conflicts:
#	lib/hammer_plug.ex
@towhans
Copy link
Contributor Author

towhans commented Dec 23, 2024

Thanks @epinault Rebased.

@epinault epinault merged commit 29c29a8 into ExHammer:master Dec 23, 2024
10 checks passed
@epinault
Copy link
Contributor

I created a release just for this on 3.2.0. This package is still EOL as it won t work well with how hammer was rearchitecture and this plug dont provide much benefits long terms.

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.

3 participants