-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explicitly handle DirtyTrick exception
- Loading branch information
Showing
14 changed files
with
97 additions
and
8 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
common-api/src/main/java/bitxon/common/exception/DirtyTrickException.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,8 @@ | ||
package bitxon.common.exception; | ||
|
||
public class DirtyTrickException extends RuntimeException { | ||
|
||
public DirtyTrickException(String message) { | ||
super("Dirty Trick: " + message); | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
dropwizard-app/src/main/java/bitxon/dropwizard/errorhandler/DirtyTrickExceptionHandler.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,20 @@ | ||
package bitxon.dropwizard.errorhandler; | ||
|
||
import bitxon.common.api.model.error.ErrorResponse; | ||
import bitxon.common.exception.DirtyTrickException; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
import java.util.List; | ||
|
||
@Provider | ||
public class DirtyTrickExceptionHandler implements ExceptionMapper<DirtyTrickException> { | ||
|
||
@Override | ||
public Response toResponse(DirtyTrickException ex) { | ||
return Response | ||
.status(500) | ||
.entity(new ErrorResponse(List.of(ex.getMessage()))).build(); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
micronaut-app/src/main/java/bitxon/micronaut/errorhandler/DirtyTrickExceptionHandler.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,25 @@ | ||
package bitxon.micronaut.errorhandler; | ||
|
||
import bitxon.common.api.model.error.ErrorResponse; | ||
import bitxon.common.exception.DirtyTrickException; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.http.HttpRequest; | ||
import io.micronaut.http.HttpResponse; | ||
import io.micronaut.http.HttpStatus; | ||
import io.micronaut.http.annotation.Produces; | ||
import io.micronaut.http.server.exceptions.ExceptionHandler; | ||
import jakarta.inject.Singleton; | ||
|
||
import java.util.List; | ||
|
||
@Produces | ||
@Singleton | ||
@Requires(classes = {DirtyTrickException.class, ExceptionHandler.class}) | ||
public class DirtyTrickExceptionHandler implements ExceptionHandler<DirtyTrickException, HttpResponse> { | ||
@Override | ||
public HttpResponse handle(HttpRequest request, DirtyTrickException ex) { | ||
return HttpResponse | ||
.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body(new ErrorResponse(List.of(ex.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
20 changes: 20 additions & 0 deletions
20
quarkus-app/src/main/java/bitxon/quarkus/errorhandler/DirtyTrickExceptionHandler.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,20 @@ | ||
package bitxon.quarkus.errorhandler; | ||
|
||
import bitxon.common.api.model.error.ErrorResponse; | ||
import bitxon.common.exception.DirtyTrickException; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.ExceptionMapper; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
import java.util.List; | ||
|
||
@Provider | ||
public class DirtyTrickExceptionHandler implements ExceptionMapper<DirtyTrickException> { | ||
|
||
@Override | ||
public Response toResponse(DirtyTrickException ex) { | ||
return Response | ||
.status(500) | ||
.entity(new ErrorResponse(List.of(ex.getMessage()))).build(); | ||
} | ||
} |
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
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