Skip to content

Commit

Permalink
Format code
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurentTreguier committed Jul 27, 2024
1 parent ef974e8 commit dbfc64e
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public ConflictException(final String explanationValue) {
}

@Override
public Object getExplanationValue() {
public String getExplanationValue() {
return explanationValue;
}
}
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();
}
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) {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public ForbiddenException(final String explanation) {
}

@Override
public Object getExplanationValue() {
public String getExplanationValue() {
return explanation;
}
}
9 changes: 3 additions & 6 deletions src/main/java/app/fyreplace/api/exceptions/Responses.java
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();
}
}

0 comments on commit dbfc64e

Please sign in to comment.