protect-endpoints icon indicating copy to clipboard operation
protect-endpoints copied to clipboard

how custom fallback type

Open MateSoftware2023 opened this issue 1 year ago • 3 comments

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?

MateSoftware2023 avatar Dec 30 '23 05:12 MateSoftware2023

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)

DDtKey avatar Dec 30 '23 20:12 DDtKey

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

MateSoftware2023 avatar Dec 31 '23 14:12 MateSoftware2023

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 🤔

DDtKey avatar Dec 31 '23 20:12 DDtKey