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

Built-in RestDataPanacheExceptionMapper is not overridable or has higher priority #38799

Closed
slgobinath opened this issue Feb 15, 2024 · 5 comments
Labels
area/panache kind/bug Something isn't working

Comments

@slgobinath
Copy link

Describe the bug

The PanacheEntityResource implementations throws RestDataPanacheException which is handled by the built-in io.quarkus.hibernate.orm.rest.data.panache.runtime.RestDataPanacheExceptionMapper class. I want to return custom responses for certain types of RestDataPanacheExceptions but my custom ExceptionMapper is used neither in dev mode nor when I run uber jar.

This issue is similar to #7883 but not sure if the fix was specific to all exception mappers or only for NotFoundExceptionMapper.

Expected behavior

The custom ExceptionMapper implemented by the user must take precedence.

Actual behavior

The custom ExceptionMapper is not used at all. Always Quarkust runs the default RestDataPanacheExceptionMapper.

How to Reproduce?

  1. Create a rest resource extending PanacheEntityResource for an entity with generated id
  2. Create a custom exception mapper ExceptionMapper<RestDataPanacheException>
  3. Send a POST request to create an entity with an explicitly defined id
  4. Observe that the default RestDataPanacheExceptionMapper is used instead of the custom mapper

Output of uname -a or ver

Linux mypc 5.15.0-94-generic #104-Ubuntu SMP Tue Jan 9 15:25:40 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

java version "21.0.1" 2023-10-17 LTS Java(TM) SE Runtime Environment (build 21.0.1+12-LTS-29) Java HotSpot(TM) 64-Bit Server VM (build 21.0.1+12-LTS-29, mixed mode, sharing)

Quarkus version or git rev

3.7.2

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

Apache Maven 3.9.6

Additional information

No response

@slgobinath slgobinath added the kind/bug Something isn't working label Feb 15, 2024
@quarkus-bot
Copy link

quarkus-bot bot commented Feb 15, 2024

/cc @FroMage (panache), @loicmathieu (panache)

@geoand
Copy link
Contributor

geoand commented Feb 15, 2024

Can you please attach a sample application that behaves as you mention, as I tried to reproduce this and it worked as expected.

Thanks

@geoand geoand added the triage/needs-reproducer We are waiting for a reproducer. label Feb 15, 2024
@slgobinath
Copy link
Author

Hi @geoand , Thanks for the quick response.
I've created the new project here https://github.com/slgobinath/issue-38799
Here's the link to core classes:

  • PanacheEntityResource: FooResource
  • ExceptionMapper: RestDataPanacheExceptionMapper - If this class is picked up the response code must be 400 and the test will pass. Instead, if the built-in mapper is used, 500 status code will be returned and the test will fail.
  • Test class: FooResourceTest

While playing with it more I came across an interesting case.
Setting @Priority(1) to [RestDataPanacheExceptionMapper.java#L12] fixes the problem which makes sense to me - Is this is the expected behavior? I'm new to Quarkus so not sure if all custom mappers must have an explicit priority set.

However, moving the RestDataPanacheExceptionMapper class to the com.example.config package also fixes the problem which I don't know how. Again, I'm new to Quarkus so not sure if this is an expected behavior but as a novice Quarkus user, I expected it to work regardless of the location (aka package) of the class.

@geoand
Copy link
Contributor

geoand commented Feb 16, 2024

I am not sure what the problem is, but if you use quarkus-resteasy-reactive-jackson (as we recommend) instead of quarkus-resteasy-jackson, then everything works as expected

@geoand geoand removed the triage/needs-reproducer We are waiting for a reproducer. label Feb 16, 2024
@slgobinath
Copy link
Author

Thanks @geoand
Switching to quarkus-resteasy-reactive-jackson does fix the problem. Feel free to close this issue or edit it to quarkus-resteasy-jackson specific.

@geoand geoand closed this as not planned Won't fix, can't repro, duplicate, stale Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/panache kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants