Skip to content

Commit

Permalink
Respond to comments from @wcekan and @aklish
Browse files Browse the repository at this point in the history
  • Loading branch information
Clay Jensen-Reimann committed Aug 8, 2018
1 parent f4e8f83 commit 2f5a70e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 0 additions & 1 deletion elide-core/src/main/java/com/yahoo/elide/Elide.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
*/
@Slf4j
public class Elide {

@Getter private final ElideSettings elideSettings;
@Getter private final AuditLogger auditLogger;
@Getter private final DataStore dataStore;
Expand Down
18 changes: 16 additions & 2 deletions elide-core/src/main/java/com/yahoo/elide/ElideResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,37 @@

import lombok.Getter;

import java.util.Optional;

/**
* Elide response object.
*/
public class ElideResponse {
@Getter private final int responseCode;
@Getter private final String body;
@Getter private final Throwable failureReason;
@Getter private final Optional<Throwable> failureReason;

/**
* Constructor.
*
* @param responseCode HTTP response code
* @param body returned body string
*/
@Deprecated
public ElideResponse(int responseCode, String body) {
this(responseCode, body, null);
}

/**
* Constructor.
*
* @param responseCode HTTP response code
* @param body returned body string
* @param failureReason the reason the request failed
*/
public ElideResponse(int responseCode, String body, Throwable failureReason) {
this.responseCode = responseCode;
this.body = body;
this.failureReason = failureReason;
this.failureReason = Optional.ofNullable(failureReason);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.google.common.collect.ImmutableMap;
import com.yahoo.elide.Elide;
import com.yahoo.elide.ElideSettings;
import com.yahoo.elide.core.DataStoreTransaction;
Expand Down Expand Up @@ -70,7 +71,6 @@ public class GraphQLEndpoint {
public GraphQLEndpoint(
@Named("elide") Elide elide,
@Named("elideUserExtractionFunction") DefaultOpaqueUserFunction getUser) {
log.error("Started ~~");
this.elide = elide;
this.elideSettings = elide.getElideSettings();
this.getUser = getUser;
Expand Down Expand Up @@ -179,13 +179,12 @@ private Response executeGraphQLRequest(
requestScope.getPermissionExecutor().executeCommitChecks();
if (query.trim().startsWith(MUTATION)) {
if (!result.getErrors().isEmpty()) {
HashMap<String, Object> abortedResponseObject = new HashMap<String, Object>() {
{
put("errors", result.getErrors());
put("data", null);
}
};
Map<String, Object> abortedResponseObject = ImmutableMap.of(
"errors", result.getErrors(),
"data", null
);
// Do not commit. Throw OK response to process tx.close correctly.
// (default transaction implementations throw an IOException if you leave a dangling SQL transaction)
throw new WebApplicationException(
Response.ok(mapper.writeValueAsString(abortedResponseObject)).build());
}
Expand Down

0 comments on commit 2f5a70e

Please sign in to comment.