Throw NamespaceNotFoundException on NamespaceResource.get()
@@ -20,7 +20,6 @@ import com.codahale.metrics.annotation.ExceptionMetered;
import com.codahale.metrics.annotation.ResponseMetered;
import com.codahale.metrics.annotation.Timed;
import java.util.List;
-import java.util.Optional;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
@@ -30,6 +29,7 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import lombok.NonNull;
+import marquez.api.exceptions.NamespaceNotFoundException;
import marquez.api.mappers.CoreNamespaceToApiNamespaceMapper;
import marquez.api.mappers.NamespaceApiMapper;
import marquez.api.mappers.NamespaceResponseMapper;
@@ -76,13 +76,12 @@ public final class NamespaceResource {
@Produces(APPLICATION_JSON)
public Response get(@PathParam("namespace") NamespaceName namespaceName)
throws MarquezServiceException {
- final Optional<NamespaceResponse> namespaceResponse =
- namespaceService.get(namespaceName).map(NamespaceResponseMapper::map);
- if (namespaceResponse.isPresent()) {
- return Response.ok(namespaceResponse.get()).build();
- } else {
- return Response.status(Response.Status.NOT_FOUND).build();
- }
+ final Namespace namespace =
+ namespaceService
+ .get(namespaceName)
+ .orElseThrow(() -> new NamespaceNotFoundException(namespaceName));
+ final NamespaceResponse response = NamespaceResponseMapper.map(namespace);
+ return Response.ok(response).build();
}
@GET
