Skip to content

Commit

Permalink
closes #56: remove WebApplicationException from the error responses (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Senic authored Feb 16, 2023
1 parent 7cafaa6 commit ff24e79
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.stargate.sgv2.jsonapi.api.exception;

import io.stargate.sgv2.jsonapi.api.model.command.CommandResult;
import io.stargate.sgv2.jsonapi.exception.mappers.ThrowableCommandResultSupplier;
import javax.ws.rs.WebApplicationException;
import org.jboss.resteasy.reactive.RestResponse;
import org.jboss.resteasy.reactive.server.ServerExceptionMapper;

/** Tries to omit the `WebApplicationException` and just report the cause. */
public class WebApplicationExceptionMapper {

@ServerExceptionMapper
public RestResponse<CommandResult> genericExceptionMapper(WebApplicationException e) {
Throwable toReport = null != e.getCause() ? e.getCause() : e;
CommandResult commandResult = new ThrowableCommandResultSupplier(toReport).get();
return RestResponse.ok(commandResult);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ public void malformedBody() {
.then()
.statusCode(200)
.body("errors[0].message", is(not(blankString())))
.body("errors[0].exceptionClass", is("WebApplicationException"))
.body("errors[1].message", is(not(blankString())))
.body("errors[1].exceptionClass", is("JsonParseException"));
.body("errors[0].exceptionClass", is("JsonParseException"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,18 @@ public final void alreadyExists() {
public final void withReplicationFactor() {
String json =
"""
{
"createNamespace": {
"name": "%s",
"options": {
"replication": {
"class": "SimpleStrategy",
"replication_factor": 2
}
}
{
"createNamespace": {
"name": "%s",
"options": {
"replication": {
"class": "SimpleStrategy",
"replication_factor": 2
}
}
"""
}
}
"""
.formatted(DB_NAME);

given()
Expand All @@ -119,11 +119,11 @@ public final void withReplicationFactor() {
public void invalidCommand() {
String json =
"""
{
"createNamespace": {
}
}
""";
{
"createNamespace": {
}
}
""";

given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
Expand Down Expand Up @@ -167,20 +167,18 @@ public void malformedBody() {
.then()
.statusCode(200)
.body("errors[0].message", is(not(blankString())))
.body("errors[0].exceptionClass", is("WebApplicationException"))
.body("errors[1].message", is(not(blankString())))
.body("errors[1].exceptionClass", is("JsonParseException"));
.body("errors[0].exceptionClass", is("JsonParseException"));
}

@Test
public void unknownCommand() {
String json =
"""
{
"unknownCommand": {
}
}
""";
{
"unknownCommand": {
}
}
""";

given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ public void malformedBody() {
.then()
.statusCode(200)
.body("errors[0].message", is(not(blankString())))
.body("errors[0].exceptionClass", is("WebApplicationException"))
.body("errors[1].message", is(not(blankString())))
.body("errors[1].exceptionClass", is("JsonParseException"));
.body("errors[0].exceptionClass", is("JsonParseException"));
}

@Test
Expand Down

0 comments on commit ff24e79

Please sign in to comment.