Skip to content

Commit

Permalink
fix teapot responses (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
w-hayes authored Apr 8, 2024
1 parent 05e349e commit 72a2a37
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static Route postIidNewGidLink(
if (!result.isSuccess()) {
final var e = result.failed().get();
LOGGER.error(e.getLocalizedMessage(), e);
return complete(ApiModels.getHttpErrorResponse(StatusCodes.IM_A_TEAPOT));
return mapError(new MpiServiceError.InternalError(e.getLocalizedMessage()));
}
return result.get()
.linkInfo()
Expand Down Expand Up @@ -81,7 +81,7 @@ private static Route postIidGidLink(
if (!result.isSuccess()) {
final var e = result.failed().get();
LOGGER.error(e.getLocalizedMessage(), e);
return complete(ApiModels.getHttpErrorResponse(StatusCodes.IM_A_TEAPOT));
return mapError(new MpiServiceError.InternalError(e.getLocalizedMessage()));
}
return result.get()
.linkInfo()
Expand Down Expand Up @@ -160,19 +160,29 @@ private static Route getGoldenRecordAuditTrail(
final ActorRef<BackEnd.Event> backEnd) {
return parameter("gid",
uid -> onComplete(Ask.getGoldenRecordAuditTrail(actorSystem, backEnd, uid),
result -> result.isSuccess()
? complete(StatusCodes.OK, result.get().auditTrail(), JSON_MARSHALLER)
: complete(ApiModels.getHttpErrorResponse(StatusCodes.IM_A_TEAPOT))));
result -> {
if (!result.isSuccess()) {
final var e = result.failed().get();
LOGGER.error(e.getLocalizedMessage(), e);
return mapError(new MpiServiceError.InternalError(e.getLocalizedMessage()));
}
return complete(StatusCodes.OK, result.get().auditTrail(), JSON_MARSHALLER);
}));
}

private static Route getInteractionAuditTrail(
final ActorSystem<Void> actorSystem,
final ActorRef<BackEnd.Event> backEnd) {
return parameter("iid",
uid -> onComplete(Ask.getInteractionAuditTrail(actorSystem, backEnd, uid),
result -> result.isSuccess()
? complete(StatusCodes.OK, result.get().auditTrail(), JSON_MARSHALLER)
: complete(ApiModels.getHttpErrorResponse(StatusCodes.IM_A_TEAPOT))));
result -> {
if (!result.isSuccess()) {
final var e = result.failed().get();
LOGGER.error(e.getLocalizedMessage(), e);
return mapError(new MpiServiceError.InternalError(e.getLocalizedMessage()));
}
return complete(StatusCodes.OK, result.get().auditTrail(), JSON_MARSHALLER);
}));
}

private static Route countGoldenRecords(
Expand Down Expand Up @@ -543,56 +553,6 @@ private static CompletionStage<Boolean> processOnNotificationResolution(

}

/*
private static CompletionStage<HttpResponse> postLinkInteractionToGidProxy(
final String linkerIP,
final Integer linkerPort,
final Http http,
final ApiModels.LinkInteractionToGidSyncBody body) throws JsonProcessingException {
final HttpRequest request;
final byte[] json;
try {
json = OBJECT_MAPPER.writeValueAsBytes(body);
} catch (JsonProcessingException e) {
LOGGER.error(e.getLocalizedMessage(), e);
throw e;
}
request = HttpRequest.create(String.format(Locale.ROOT,
"http://%s:%d/JeMPI/%s",
linkerIP,
linkerPort,
GlobalConstants.SEGMENT_PROXY_POST_LINK_INTERACTION_TO_GID))
.withMethod(HttpMethods.POST)
.withEntity(ContentTypes.APPLICATION_JSON, json);
final var stage = http.singleRequest(request);
return stage.thenApply(response -> response);
}
*/

/*
private static Route postLinkInteractionToGid(
final String linkerIP,
final Integer linkerPort,
final Http http) {
return entity(Jackson.unmarshaller(OBJECT_MAPPER, ApiModels.LinkInteractionToGidSyncBody.class),
obj -> {
try {
return onComplete(postLinkInteractionToGidProxy(linkerIP, linkerPort, http, obj),
response -> {
if (!response.isSuccess()) {
LOGGER.warn(IM_A_TEA_POT_LOG);
return complete(ApiModels.getHttpErrorResponse(GlobalConstants.IM_A_TEA_POT));
}
return complete(response.get());
});
} catch (JsonProcessingException e) {
LOGGER.error(e.getLocalizedMessage(), e);
return complete(ApiModels.getHttpErrorResponse(StatusCodes.UNPROCESSABLE_ENTITY));
}
});
}
*/

public static Route createCoreAPIRoutes(
final ActorSystem<Void> actorSystem,
final ActorRef<BackEnd.Event> backEnd,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public final class GlobalConstants {
public static final String SEGMENT_LOGOUT = "logout";
public static final String SEGMENT_CURRENT_USER = "currentUser";

// public static final StatusCode IM_A_TEA_POT = StatusCodes.IM_A_TEAPOT;
// TIMEOUTS
public static final int TIMEOUT_DGRAPH_RECONNECT_RETRIES = 20;
public static final int TIMEOUT_DGRAPH_RECONNECT_SLEEP_SECS = 2;
Expand Down

0 comments on commit 72a2a37

Please sign in to comment.