-
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.
- Loading branch information
1 parent
ef974e8
commit dbfc64e
Showing
5 changed files
with
9 additions
and
9 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
2 changes: 1 addition & 1 deletion
2
src/main/java/app/fyreplace/api/exceptions/ExplainableException.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,5 +1,5 @@ | ||
package app.fyreplace.api.exceptions; | ||
|
||
public interface ExplainableException { | ||
Object getExplanationValue(); | ||
String getExplanationValue(); | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/app/fyreplace/api/exceptions/ExplainedFailure.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,3 @@ | ||
package app.fyreplace.api.exceptions; | ||
|
||
public record ExplainedFailure(String title, int status, String reason) {} |
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 |
---|---|---|
@@ -1,16 +1,13 @@ | ||
package app.fyreplace.api.exceptions; | ||
|
||
import io.vertx.core.json.JsonObject; | ||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.Response; | ||
|
||
public final class Responses { | ||
public static <E extends WebApplicationException & ExplainableException> Response makeFrom(final E exception) { | ||
final var response = exception.getResponse(); | ||
final var body = new JsonObject() | ||
.put("title", response.getStatusInfo().getReasonPhrase()) | ||
.put("status", response.getStatus()) | ||
.put("reason", exception.getExplanationValue()); | ||
return Response.status(response.getStatus()).entity(body).build(); | ||
final var failure = new ExplainedFailure( | ||
response.getStatusInfo().getReasonPhrase(), response.getStatus(), exception.getExplanationValue()); | ||
return Response.status(response.getStatus()).entity(failure).build(); | ||
} | ||
} |