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

@RolesAllowed wrap all exception with RuntimeException of asynchronous rest client when CompletionStage is not created #21679

Closed
carmelowise opened this issue Nov 24, 2021 · 2 comments · Fixed by #21763
Labels
area/rest-client kind/bug Something isn't working
Milestone

Comments

@carmelowise
Copy link

carmelowise commented Nov 24, 2021

Describe the bug

This is my method on my rest interface

    @GET
    @Path("/hello2")
    @RolesAllowed("v1.ro")
    @Produces(MediaType.TEXT_PLAIN)
    public CompletionStage<String> hello() {
        throw new RepositoryBadRequestException("hello world");
    }

this is the custom Exception:

public class RepositoryBadRequestException extends RuntimeException {
  public RepositoryBadRequestException(String message) {
    super(message);
  }
}

this is the exception mapper

@Provider
public class RepositoryBadRequestExceptionMapper implements ExceptionMapper<RepositoryBadRequestException> {
  @Override
  public Response toResponse(RepositoryBadRequestException e) {
    return Response.status(400)
                   .entity(e.getMessage())
                   .type(APPLICATION_JSON)
                   .build();
  }
}

the toResponse method does not trigger because the exception is Wrapped in a RuntimeException by io.quarkus.security.runtime.interceptor.SecurityHandler.java.

This is the snipped of the code in SecurityHandler.java that wrap the exception:
line 36 to 40

try {
    return Uni.createFrom().completionStage((CompletionStage<?>) ic.proceed());
} catch (Exception e) {
    throw new RuntimeException(e);
}

Expected behavior

The method hello return http code 400.

Actual behavior

The method hello return http code 500.

How to Reproduce?

  1. download and unzip this file

code-bug-security-handler.zip

  1. run the project mvn compile quakus:dev
  2. import the postman collection from postman folder
  3. send request

Output of uname -a or ver

Darwin MacBookPro.local 20.6.0 Darwin Kernel Version 20.6.0: Mon Aug 30 06:12:20 PDT 2021; root:xnu-7195.141.6~3/RELEASE_ARM64_T8101 arm64

Output of java -version

java version "17" 2021-09-14 LTS Java(TM) SE Runtime Environment (build 17+35-LTS-2724) Java HotSpot(TM) 64-Bit Server VM (build 17+35-LTS-2724, mixed mode, sharing)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.5.0.Final

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739) Maven home: /opt/homebrew/Cellar/maven/3.8.3/libexec Java version: 17, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home Default locale: it_IT, platform encoding: UTF-8 OS name: "mac os x", version: "11.6", arch: "aarch64", family: "mac"

Additional information

No response

@carmelowise carmelowise added the kind/bug Something isn't working label Nov 24, 2021
@quarkus-bot
Copy link

quarkus-bot bot commented Nov 24, 2021

/cc @michalszynkiewicz

@carmelowise
Copy link
Author

carmelowise commented Nov 24, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/rest-client kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants