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

Transform the Error of a FromRequest of an Either is now impossible #3541

Open
axos88 opened this issue Jan 1, 2025 · 0 comments
Open

Transform the Error of a FromRequest of an Either is now impossible #3541

axos88 opened this issue Jan 1, 2025 · 0 comments
Labels
A-web project: actix-web C-chore Category: chore good-first-issue easy to pick up for newcomers

Comments

@axos88
Copy link
Contributor

axos88 commented Jan 1, 2025

Creating a FromRequest for a type that uses a FromRequest of an Either under the hood is now impossible to the opaque error type of the EitherExtractFut.

Migrating the following code post 4.0.0 seems impossible:

pub enum Permission {... }
pub struct Permissions(HashSet<Permission>);
pub type AuthInfo = Either<Auth0AuthData, ApiKeyAuthData>;

impl FromRequest for Auth0AuthData { ... }
impl FromRequest for ApiKeyAuthData { ... }


impl FromRequest for Permissions {
  type Error = PermissionError;
  type Future = ResponseFuture<Result<Permissions, PermissionError>>;

  fn from_request(req: &HttpRequest, _payload: &mut Payload) -> Self::Future {
    let auth_info_fut = AuthInfo::extract(req);

    let f = async move {
      let auth_info = auth_info_fut.await.map_err(|e| match e {
        EitherExtractError::Bytes(e) => PermissionError::Other(e.to_string()),
        EitherExtractError::Extract(PermissionError::NoCredentials, r) => r,
        EitherExtractError::Extract(l, _) => l,
      )?;

      match auth_info {
        Either::Left(auth0) => auth0.permissions(&config_addr).await,
        Either::Right(ApiKey { permissions, .. }) => Ok(Permissions(permissions)),
      }
    };

    Box::pin(f)
  }
}

Expected Behavior

EitherExtractError should be accessible

Current Behavior

It's opaque

Possible Solution

Revert the removal from the public api

Steps to Reproduce (for bugs)

Context

Your Environment

  • Rust Version (I.e, output of rustc -V):
  • Actix Web Version: 4.0.0-beta-10
@robjtede robjtede added B-semver-patch C-chore Category: chore A-web project: actix-web good-first-issue easy to pick up for newcomers and removed B-semver-patch labels Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-web project: actix-web C-chore Category: chore good-first-issue easy to pick up for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants