Skip to content

Commit

Permalink
Fix response status if not found (#39) (#40)
Browse files Browse the repository at this point in the history
Signed-off-by: yichen88 <[email protected]>
  • Loading branch information
yichen88 authored Jun 29, 2020
1 parent 9512ce2 commit f47a619
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
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) {
LOGGER.trace(" --> null");
return Optional.empty();
} 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

0 comments on commit f47a619

Please sign in to comment.