From 7b5c4827c5c33fb131d5714d0b97aae3e3ab06f0 Mon Sep 17 00:00:00 2001 From: HuaizhiDai Date: Wed, 25 Sep 2024 14:33:41 +1000 Subject: [PATCH 1/3] return 404 if didn't find an uuid --- .../java/au/org/aodn/ogcapi/server/features/RestServices.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java b/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java index 95be7548..00e0fd8c 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java @@ -39,7 +39,7 @@ public ResponseEntity getCollection(String id, String sortBy) throws return ResponseEntity.ok() .body(StacToCollection.convert(model.getCollections().get(0))); } else { - throw new NoSuchElementException(String.format("uuid %s not found!", id)); + return ResponseEntity.notFound().build(); } } } From 1f7f5eb29c771b77c70d4d6d4db6c88fedd12cca Mon Sep 17 00:00:00 2001 From: HuaizhiDai Date: Wed, 25 Sep 2024 15:53:37 +1000 Subject: [PATCH 2/3] test fixed --- .../aodn/ogcapi/server/common/RestApiTest.java | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/server/src/test/java/au/org/aodn/ogcapi/server/common/RestApiTest.java b/server/src/test/java/au/org/aodn/ogcapi/server/common/RestApiTest.java index 37394423..3396a2d8 100644 --- a/server/src/test/java/au/org/aodn/ogcapi/server/common/RestApiTest.java +++ b/server/src/test/java/au/org/aodn/ogcapi/server/common/RestApiTest.java @@ -2,14 +2,10 @@ import au.org.aodn.ogcapi.features.model.Collections; import au.org.aodn.ogcapi.server.BaseTestClass; - import au.org.aodn.ogcapi.server.core.model.ErrorResponse; import au.org.aodn.ogcapi.server.core.model.ExtendedCollections; import au.org.aodn.ogcapi.server.core.model.enumeration.OGCMediaTypeMapper; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.*; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpMethod; @@ -28,9 +24,6 @@ @TestInstance(TestInstance.Lifecycle.PER_CLASS) // We need to use @BeforeAll @AfterAll with not static method public class RestApiTest extends BaseTestClass { - @Autowired - protected ObjectMapper objectMapper; - @BeforeAll public void beforeClass() { super.createElasticIndex(); @@ -514,14 +507,10 @@ public void verifyCQLFuzzyKey() throws IOException { * on any error */ @Test - public void verifyErrorMessageCreated() throws JsonProcessingException { + public void verifyErrorMessageCreated() { ResponseEntity collection = testRestTemplate.getForEntity(getBasePath() + "/collections/12324", String.class); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, collection.getStatusCode(), "Request Status match"); - - ErrorResponse response = objectMapper.readValue(Objects.requireNonNull(collection.getBody()), ErrorResponse.class); - assertEquals("uuid 12324 not found!", response.getMessage(), "message match"); - assertEquals("uri=/api/v1/ogc/collections/12324", response.getDetails(), "message url"); + assertEquals(HttpStatus.NOT_FOUND, collection.getStatusCode(), "Request Status match"); } /** * Test sort by, you can use this as an example for how ot use sortBy From 295b9275fcf5da4b9b1033f796982d4e4c1169bd Mon Sep 17 00:00:00 2001 From: HuaizhiDai Date: Wed, 25 Sep 2024 16:29:41 +1000 Subject: [PATCH 3/3] add log error to print didn't find a uuid --- .../java/au/org/aodn/ogcapi/server/features/RestServices.java | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java b/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java index 00e0fd8c..d9a73921 100644 --- a/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java +++ b/server/src/main/java/au/org/aodn/ogcapi/server/features/RestServices.java @@ -39,6 +39,7 @@ public ResponseEntity getCollection(String id, String sortBy) throws return ResponseEntity.ok() .body(StacToCollection.convert(model.getCollections().get(0))); } else { + log.error("UUID {} not found", id); return ResponseEntity.notFound().build(); } }