-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use @ServerExceptionMapper instead of JaxRS ExceptionMappers to fix m…
…igrating to `quarkus-rest-jackson`. Also implements some simplification of error handling etc. There can still be some improvements but this is passing tests for now. Signed-off-by: appiepollo14 <[email protected]>
- Loading branch information
1 parent
1d17379
commit bdeb1ab
Showing
16 changed files
with
83 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 1 addition & 6 deletions
7
src/main/java/org/example/realworldapi/domain/exception/ArticleNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
package org.example.realworldapi.domain.exception; | ||
|
||
public class ArticleNotFoundException extends BusinessException { | ||
|
||
public ArticleNotFoundException() { | ||
super(5, "article not found"); | ||
} | ||
} | ||
public class ArticleNotFoundException extends RuntimeException {} |
13 changes: 0 additions & 13 deletions
13
src/main/java/org/example/realworldapi/domain/exception/BusinessException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 1 addition & 5 deletions
6
src/main/java/org/example/realworldapi/domain/exception/CommentNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
package org.example.realworldapi.domain.exception; | ||
|
||
public class CommentNotFoundException extends BusinessException { | ||
public CommentNotFoundException() { | ||
super(6, "comment not found"); | ||
} | ||
} | ||
public class CommentNotFoundException extends RuntimeException {} |
5 changes: 2 additions & 3 deletions
5
src/main/java/org/example/realworldapi/domain/exception/EmailAlreadyExistsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
package org.example.realworldapi.domain.exception; | ||
|
||
public class EmailAlreadyExistsException extends BusinessException { | ||
|
||
public class EmailAlreadyExistsException extends RuntimeException { | ||
public EmailAlreadyExistsException() { | ||
super(3, "email already exists"); | ||
super("email already exists"); | ||
} | ||
} |
6 changes: 1 addition & 5 deletions
6
src/main/java/org/example/realworldapi/domain/exception/InvalidPasswordException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,3 @@ | ||
package org.example.realworldapi.domain.exception; | ||
|
||
public class InvalidPasswordException extends BusinessException { | ||
public InvalidPasswordException() { | ||
super(4, "invalid password"); | ||
} | ||
} | ||
public class InvalidPasswordException extends RuntimeException {} |
7 changes: 1 addition & 6 deletions
7
src/main/java/org/example/realworldapi/domain/exception/TagNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
package org.example.realworldapi.domain.exception; | ||
|
||
public class TagNotFoundException extends BusinessException { | ||
|
||
public TagNotFoundException() { | ||
super(7, "tag not found"); | ||
} | ||
} | ||
public class TagNotFoundException extends RuntimeException {} |
5 changes: 2 additions & 3 deletions
5
src/main/java/org/example/realworldapi/domain/exception/UserNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
package org.example.realworldapi.domain.exception; | ||
|
||
public class UserNotFoundException extends BusinessException { | ||
|
||
public class UserNotFoundException extends RuntimeException { | ||
public UserNotFoundException() { | ||
super(1, "user not found"); | ||
super("user not found"); | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
src/main/java/org/example/realworldapi/domain/exception/UsernameAlreadyExistsException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
package org.example.realworldapi.domain.exception; | ||
|
||
public class UsernameAlreadyExistsException extends BusinessException { | ||
|
||
public class UsernameAlreadyExistsException extends RuntimeException { | ||
public UsernameAlreadyExistsException() { | ||
super(2, "username already exists"); | ||
super("username already exists"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
...main/java/org/example/realworldapi/infrastructure/web/mapper/BusinessExceptionMapper.java
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
src/main/java/org/example/realworldapi/infrastructure/web/mapper/ExceptionMappers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.example.realworldapi.infrastructure.web.mapper; | ||
|
||
import jakarta.ws.rs.core.Response; | ||
import org.example.realworldapi.application.web.model.response.ErrorResponse; | ||
import org.example.realworldapi.domain.exception.*; | ||
import org.jboss.resteasy.reactive.server.ServerExceptionMapper; | ||
|
||
public class ExceptionMappers { | ||
|
||
@ServerExceptionMapper | ||
public Response emailAlreadyExists(EmailAlreadyExistsException e) { | ||
return Response.ok(errorResponse(e)).status(Response.Status.CONFLICT.getStatusCode()).build(); | ||
} | ||
|
||
@ServerExceptionMapper | ||
public Response usernameAlreadyExists(UsernameAlreadyExistsException e) { | ||
return Response.ok(errorResponse(e)).status(Response.Status.CONFLICT.getStatusCode()).build(); | ||
} | ||
|
||
@ServerExceptionMapper | ||
public Response userNotfound(UserNotFoundException e) { | ||
return Response.ok(errorResponse(e)).status(Response.Status.NOT_FOUND.getStatusCode()).build(); | ||
} | ||
|
||
@ServerExceptionMapper | ||
public Response invalidPassword(InvalidPasswordException e) { | ||
return Response.ok(errorResponse(e)) | ||
.status(Response.Status.UNAUTHORIZED.getStatusCode()) | ||
.build(); | ||
} | ||
|
||
@ServerExceptionMapper | ||
public Response tagNotFound(TagNotFoundException e) { | ||
return Response.ok(errorResponse(e)).status(Response.Status.NOT_FOUND.getStatusCode()).build(); | ||
} | ||
|
||
@ServerExceptionMapper | ||
public Response articleNotFound(ArticleNotFoundException e) { | ||
return Response.ok(errorResponse(e)).status(Response.Status.NOT_FOUND.getStatusCode()).build(); | ||
} | ||
|
||
@ServerExceptionMapper | ||
public Response modelValidation(ModelValidationException e) { | ||
return Response.ok(errorResponse(e)).status(422).build(); | ||
} | ||
|
||
private ErrorResponse errorResponse(RuntimeException e) { | ||
return new ErrorResponse(e.getMessage()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,14 @@ | |
import org.junit.jupiter.api.Test; | ||
|
||
@QuarkusTest | ||
public class UsersResourceIntegrationTest extends AbstractIntegrationTest { | ||
class UsersResourceIntegrationTest extends AbstractIntegrationTest { | ||
|
||
private final String USERS_RESOURCE_PATH = API_PREFIX + "/users"; | ||
private final String LOGIN_PATH = USERS_RESOURCE_PATH + "/login"; | ||
|
||
@Test | ||
public void | ||
givenAValidUser_whenCallingRegisterUserEndpoint_thenReturnAnUserWithTokenFieldAndCode201() | ||
throws JsonProcessingException { | ||
void givenAValidUser_whenCallingRegisterUserEndpoint_thenReturnAnUserWithTokenFieldAndCode201() | ||
throws JsonProcessingException { | ||
|
||
NewUserRequest newUser = new NewUserRequest(); | ||
newUser.setUsername("user"); | ||
|
@@ -56,9 +55,8 @@ public class UsersResourceIntegrationTest extends AbstractIntegrationTest { | |
} | ||
|
||
@Test | ||
public void | ||
givenAPersistedUser_whenCallingRegisterUserEndpointWithExistingEmail_thenReturnCode409() | ||
throws JsonProcessingException { | ||
void givenAPersistedUser_whenCallingRegisterUserEndpointWithExistingEmail_thenReturnCode409() | ||
throws JsonProcessingException { | ||
|
||
String userPassword = "123"; | ||
|
||
|
@@ -80,9 +78,8 @@ public class UsersResourceIntegrationTest extends AbstractIntegrationTest { | |
} | ||
|
||
@Test | ||
public void | ||
givenAPersistedUser_whenCallingRegisterUserEndpointWithExistingUsername_thenReturnCode409() | ||
throws JsonProcessingException { | ||
void givenAPersistedUser_whenCallingRegisterUserEndpointWithExistingUsername_thenReturnCode409() | ||
throws JsonProcessingException { | ||
|
||
String userPassword = "123"; | ||
|
||
|
@@ -104,7 +101,7 @@ public class UsersResourceIntegrationTest extends AbstractIntegrationTest { | |
} | ||
|
||
@Test | ||
public void givenAnInvalidUser_thenReturnErrorsWith422Code() throws JsonProcessingException { | ||
void givenAnInvalidUser_thenReturnErrorsWith422Code() throws JsonProcessingException { | ||
|
||
NewUserRequest newUser = new NewUserRequest(); | ||
|
||
|
@@ -126,7 +123,7 @@ public void givenAnInvalidUser_thenReturnErrorsWith422Code() throws JsonProcessi | |
} | ||
|
||
@Test | ||
public void givenAnInvalidEmail_thenReturnErrorsWith422Code() throws JsonProcessingException { | ||
void givenAnInvalidEmail_thenReturnErrorsWith422Code() throws JsonProcessingException { | ||
|
||
NewUserRequest newUser = new NewUserRequest(); | ||
newUser.setUsername("username"); | ||
|
@@ -148,7 +145,7 @@ public void givenAnInvalidEmail_thenReturnErrorsWith422Code() throws JsonProcess | |
} | ||
|
||
@Test | ||
public void givenAInvalidLogin_whenExecuteLoginEndpoint_shouldReturnErrorsWith422Code() | ||
void givenAInvalidLogin_whenExecuteLoginEndpoint_shouldReturnErrorsWith422Code() | ||
throws JsonProcessingException { | ||
|
||
LoginRequest loginRequest = new LoginRequest(); | ||
|
@@ -164,7 +161,7 @@ public void givenAInvalidLogin_whenExecuteLoginEndpoint_shouldReturnErrorsWith42 | |
} | ||
|
||
@Test | ||
public void givenAInvalidLoginEmail_whenExecuteLoginEndpoint_shouldReturnUnauthorized() | ||
void givenAInvalidLoginEmail_whenExecuteLoginEndpoint_shouldReturnUnauthorized() | ||
throws JsonProcessingException { | ||
|
||
String userPassword = "123"; | ||
|
@@ -184,7 +181,7 @@ public void givenAInvalidLoginEmail_whenExecuteLoginEndpoint_shouldReturnUnautho | |
} | ||
|
||
@Test | ||
public void givenAInvalidLoginPassword_whenExecuteLoginEndpoint_shouldReturnUnauthorized() | ||
void givenAInvalidLoginPassword_whenExecuteLoginEndpoint_shouldReturnUnauthorized() | ||
throws JsonProcessingException { | ||
|
||
final var user = createUserEntity("user1", "[email protected]", "123", "bio", "image"); | ||
|