Skip to content

Commit 39830fb

Browse files
provide reason for json processing exception
Signed-off-by: Pawel Leszczynski <leszczynski.pawel@gmail.com>
1 parent 0c78cd8 commit 39830fb

4 files changed

Lines changed: 54 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## [Unreleased](https://github.com/MarquezProject/marquez/compare/0.28.0...HEAD)
44

5+
* Include error message for JSON processing exception [`#2271`](https://github.com/MarquezProject/marquez/pull/2271) [@pawel-big-lebowski](https://github.com/pawel-big-lebowski)
6+
*In case of JSON processing exceptions Marquez API should return exception message to a client.*
7+
58
## [0.28.0](https://github.com/MarquezProject/marquez/compare/0.27.0...0.28.0) - 2022-11-21
69

710
### Added

api/src/main/java/marquez/MarquezContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import marquez.api.SourceResource;
2323
import marquez.api.TagResource;
2424
import marquez.api.exceptions.JdbiExceptionExceptionMapper;
25+
import marquez.api.exceptions.JsonProcessingExceptionMapper;
2526
import marquez.db.BaseDao;
2627
import marquez.db.ColumnLineageDao;
2728
import marquez.db.DatasetDao;
@@ -96,6 +97,7 @@ public final class MarquezContext {
9697
@Getter private final SearchResource searchResource;
9798
@Getter private final ImmutableList<Object> resources;
9899
@Getter private final JdbiExceptionExceptionMapper jdbiException;
100+
@Getter private final JsonProcessingExceptionMapper jsonException;
99101
@Getter private final GraphQLHttpServlet graphqlServlet;
100102

101103
private MarquezContext(
@@ -137,6 +139,7 @@ private MarquezContext(
137139
this.lineageService = new LineageService(lineageDao, jobDao);
138140
this.columnLineageService = new ColumnLineageService(columnLineageDao, datasetFieldDao);
139141
this.jdbiException = new JdbiExceptionExceptionMapper();
142+
this.jsonException = new JsonProcessingExceptionMapper();
140143
final ServiceFactory serviceFactory =
141144
ServiceFactory.builder()
142145
.datasetService(datasetService)
@@ -169,6 +172,7 @@ private MarquezContext(
169172
jobResource,
170173
tagResource,
171174
jdbiException,
175+
jsonException,
172176
openLineageResource,
173177
searchResource);
174178

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2018-2022 contributors to the Marquez project
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package marquez.api.exceptions;
7+
8+
import static javax.ws.rs.core.MediaType.APPLICATION_JSON_TYPE;
9+
import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
10+
11+
import com.fasterxml.jackson.core.JsonProcessingException;
12+
import io.dropwizard.jersey.errors.ErrorMessage;
13+
import javax.ws.rs.core.Response;
14+
import javax.ws.rs.ext.ExceptionMapper;
15+
import lombok.extern.slf4j.Slf4j;
16+
17+
@Slf4j
18+
public class JsonProcessingExceptionMapper implements ExceptionMapper<JsonProcessingException> {
19+
20+
@Override
21+
public Response toResponse(JsonProcessingException e) {
22+
log.error("Failed to process JSON", e);
23+
return Response.serverError()
24+
.type(APPLICATION_JSON_TYPE)
25+
.entity(new ErrorMessage(BAD_REQUEST.getStatusCode(), e.getMessage()))
26+
.build();
27+
}
28+
}

api/src/test/java/marquez/OpenLineageIntegrationTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,25 @@ public void testSendOpenLineageEventFailsValidation(String eventBody) throws IOE
150150
assertThat(resp.join()).isEqualTo(422);
151151
}
152152

153+
@Test
154+
public void testSendOpenLineageEventFailsJsonProcessing() throws IOException {
155+
String eventWithIncorrectEventTimeFormat =
156+
"{\"eventTime\": \"2021-11-03\", \"eventType\": \"START\", \"inputs\": [], \"job\": {\"facets\": {}, \"name\": \"job\", \"namespace\": \"openlineage\"}, \"outputs\": [], \"run\": {\"facets\": {}, \"runId\": \"123e4567-e89b-12d3-a456-426614174000\"}}";
157+
158+
final CompletableFuture<String> resp =
159+
this.sendLineage(eventWithIncorrectEventTimeFormat)
160+
.thenApply(HttpResponse::body)
161+
.whenComplete(
162+
(val, err) -> {
163+
if (err != null) {
164+
Assertions.fail("Could not complete request");
165+
}
166+
});
167+
assertThat(resp.join())
168+
.contains(
169+
"Cannot deserialize value of type `java.time.ZonedDateTime` from String \\\"2021-11-03\\\"");
170+
}
171+
153172
@Test
154173
public void testGetLineageForNonExistantDataset() {
155174
CompletableFuture<Integer> response =

0 commit comments

Comments
 (0)