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

how custom fallback type #68

Open
MateSoftware2023 opened this issue Dec 30, 2023 · 3 comments
Open

how custom fallback type #68

MateSoftware2023 opened this issue Dec 30, 2023 · 3 comments
Labels
question Further information is requested

Comments

@MateSoftware2023
Copy link

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
Copy link
Owner

DDtKey commented Dec 30, 2023

Hi!
Yes, it's possible, take a look at #26 (issue) and test of the functionality:

fn access_denied() -> HttpResponse {
HttpResponse::with_body(
StatusCode::FORBIDDEN,
BoxBody::new("This resource allowed only for ADMIN"),
)
}
#[get("/access")]
#[protect("ROLE_ADMIN", error = "access_denied")]
async fn access_response() -> &'static str {
"Hi!"
}

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

@DDtKey DDtKey added the question Further information is requested label Dec 30, 2023
@MateSoftware2023
Copy link
Author

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
Copy link
Owner

DDtKey commented Dec 31, 2023

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 🤔

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

No branches or pull requests

2 participants