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

Fix response status if not found (#39) #40

Merged
merged 4 commits into from
Jun 29, 2020
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 @@ -93,7 +93,6 @@ public static <T> T readEntityIfOk(Response response, Class<T> entityType) {
} else {
throw createUnexpectedResponseStatus(status);
}

}

public static <T> T readEntityIfOk(Response response, GenericType<T> entityType) {
Expand All @@ -114,16 +113,13 @@ public static <T> T readEntityIfOk(Response response, GenericType<T> entityType)

public static <T> Optional<T> readOptionalEntityIfOk(Response response, Class<T> entityType) {
Response.Status status = Response.Status.fromStatusCode(response.getStatus());
if (status == Response.Status.OK) {
return Optional.of(readEntityAndLog(response, entityType));
} else if (status == Response.Status.NO_CONTENT) {
// the NO_CONTENT case is for backwards compatibility.
// The remote AppStorageServer may still runs on an old version which response with 204 if it not found resources.
if (status == Response.Status.NO_CONTENT || status == Response.Status.NOT_FOUND) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment that the NO_CONTENT is for backwards compatibility with afs-server < version XX

LOGGER.trace(" --> null");
return Optional.empty();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove the INTERNAL_SERVER_ERROR case ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and the UnexpectedResponse case ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these cases are still checked in readEntityIfOk().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes sorry, didn't see it.

} else if (status == Response.Status.INTERNAL_SERVER_ERROR) {
throw createServerErrorException(response);
} else {
throw createUnexpectedResponseStatus(status);
}
return Optional.of(readEntityIfOk(response, entityType));
}

public static UserSession authenticate(URI baseUri, String login, String password) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import com.powsybl.afs.storage.NodeGenericMetadata;
import com.powsybl.afs.storage.NodeInfo;
import com.powsybl.afs.storage.buffer.*;
import com.powsybl.afs.ws.server.utils.JwtTokenNeeded;
import com.powsybl.afs.ws.server.utils.AppDataBean;
import com.powsybl.afs.ws.server.utils.JwtTokenNeeded;
import com.powsybl.afs.ws.utils.AfsRestApi;
import com.powsybl.afs.ws.utils.gzip.Compress;
import com.powsybl.timeseries.DoubleDataChunk;
Expand Down Expand Up @@ -109,7 +109,7 @@ public Response createNode(@ApiParam(value = "File system name") @PathParam("fil
@ApiParam(value = "Version") @QueryParam("version") int version,
@ApiParam(value = "Node Meta Data") NodeGenericMetadata nodeMetadata) {
AppStorage storage = appDataBean.getStorage(fileSystemName);
NodeInfo newNodeInfo = storage.createNode(nodeId, childName, nodePseudoClass, description, version, nodeMetadata);
NodeInfo newNodeInfo = storage.createNode(nodeId, childName, nodePseudoClass, description, version, nodeMetadata);
return Response.ok().entity(newNodeInfo).build();
}

Expand Down Expand Up @@ -138,7 +138,7 @@ public Response getParentNode(@ApiParam(value = "File system name") @PathParam("
if (parentNodeInfo.isPresent()) {
return Response.ok().entity(parentNodeInfo.get()).build();
} else {
return Response.noContent().build();
return Response.status(Status.NOT_FOUND).build();
}
}

Expand All @@ -155,7 +155,7 @@ public Response getChildNode(@ApiParam(value = "File system name") @PathParam("f
if (childNodeInfo.isPresent()) {
return Response.status(Status.OK).entity(childNodeInfo.get()).build();
} else {
return Response.status(Status.NO_CONTENT).build();
return Response.status(Status.NOT_FOUND).build();
}
}

Expand Down