Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #56: remove WebApplicationException from the error responses #119

Merged
merged 1 commit into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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