DDtKey / protect-endpoints

Authorization extension for popular web-frameworks to protect your endpoints
Apache License 2.0
216 stars 16 forks source link

how custom fallback type #68

Open MateSoftware2023 opened 11 months ago

MateSoftware2023 commented 11 months ago

hi im new user for this framework i want return cutom type if user no permission, return json format not 403 only , how to do?

DDtKey commented 10 months ago

Hi! Yes, it's possible, take a look at #26 (issue) and test of the functionality: https://github.com/DDtKey/protect-endpoints/blob/e86976ff0667f7441a44416c9aa94dee579e7d11/actix-web-grants/tests/proc_macro/different_fn_types.rs#L47-L58

This partly depends on the framework you are using. You can also use error catchers (at least for poem & rocket)

MateSoftware2023 commented 10 months ago

thanks. That's the way I'm using it now It would be better to have a global configuration instead of using it everywhere

DDtKey commented 10 months ago

I think catchers on web-framework level is more suitable for global handling.

However, I think we might introduce something like a custom error-generator(configurable as part of middleware) and use user's defined function in macro without explicit attribute 🤔