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

Added error logging and error messaging response when errors occur #267

Merged
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
Expand Up @@ -53,8 +53,8 @@ public void sendDataMessage(String id, Object payload) {
}

@Override
public void sendErrorMessage(String id) {

public void sendErrorMessage(String id, Object payload) {
send(mapper.serialize(payload));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
package graphql.kickstart.execution.subscriptions;

import graphql.ExecutionResult;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import graphql.GraphQLError;
import graphql.kickstart.execution.error.GenericGraphQLError;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.reactivestreams.Subscriber;
Expand All @@ -29,15 +34,20 @@ public void onSubscribe(Subscription subscription) {
public void onNext(ExecutionResult executionResult) {
Map<String, Object> result = new HashMap<>();
result.put("data", executionResult.getData());

session.sendDataMessage(id, result);
subscriptionReference.get().request(1);
}

@Override
public void onError(Throwable throwable) {
log.error("Subscription error", throwable);

Map<String, Object> payload = new HashMap<>();
payload.put("errors", Collections.singletonList(new GenericGraphQLError(throwable.getMessage())));

session.unsubscribe(id);
session.sendErrorMessage(id);
session.sendErrorMessage(id, payload);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface SubscriptionSession {

void sendDataMessage(String id, Object payload);

void sendErrorMessage(String id);
void sendErrorMessage(String id, Object payload);

void sendCompleteMessage(String id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public void sendDataMessage(String id, Object payload) {
}

@Override
public void sendErrorMessage(String id) {
sendMessage(new OperationMessage(Type.GQL_ERROR, id, null));
public void sendErrorMessage(String id, Object payload) {
sendMessage(new OperationMessage(Type.GQL_ERROR, id, payload));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public void apply(SubscriptionSession session, OperationMessage message) {
connectionListeners.forEach(it -> it.onConnect(session, message));
session.sendMessage(new OperationMessage(Type.GQL_CONNECTION_ACK, message.getId(), null));
} catch (Throwable t) {
session.sendMessage(
new OperationMessage(Type.GQL_CONNECTION_ERROR, message.getId(), t.getMessage()));
log.error("Cannot initialize subscription command '{}'", message, t);
session.sendMessage(new OperationMessage(Type.GQL_CONNECTION_ERROR, message.getId(), t.getMessage()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void onNext(String message) {

@Override
public void onError(Throwable t) {

log.error("WebSocket error", t);
}

@Override
Expand Down