Skip to content

Commit a37d427

Browse files
committed
http190 improve completion code for response parse errors
Signed-off-by: davidradl <[email protected]>
1 parent 9514c77 commit a37d427

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

CHANGELOG.md

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

33
## [Unreleased]
44

5+
- Add UNABLE_TO_DESERIALIZE_RESPONSE http-completion-state. If you have used
6+
`gid.connector.http.source.lookup.continue-on-error` in a previous release, please review your SQL or applications to
7+
account for this new http-completion-state value.
8+
59
## [0.23.0] - 2025-11-07
610

711
- Ability to specify http versions for http lookups.

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,24 @@ Metadata columns can be specified and hold http information. They are optional r
190190

191191
| Key | Data Type | Description |
192192
|-----------------------|----------------------------------|----------------------------------------|
193-
| error-string | STRING NULL | A message associated with the error |
193+
| error-string | STRING NULL | A string associated with the error |
194194
| http-status-code | INT NULL | The HTTP status code |
195195
| http-headers-map | MAP <STRING, ARRAY<STRING>> NULL | The headers returned with the response |
196196
| http-completion-state | STRING NULL | The completion state of the http call. |
197197

198198
##### http-completion-state possible values
199199

200-
| Value | Description |
201-
|:------------------|------------------------|
202-
| SUCCESS | Success |
203-
| HTTP_ERROR_STATUS | HTTP error status code |
204-
| EXCEPTION | An Exception occurred |
200+
| Value | Description |
201+
|:-------------------------------|-------------------------------------|
202+
| SUCCESS | Success |
203+
| HTTP_ERROR_STATUS | HTTP error status code |
204+
| EXCEPTION | An Exception occurred |
205+
| UNABLE_TO_DESERIALIZE_RESPONSE | Unable to deserialize HTTP response |
205206

206207
If the `error-string` metadata column is defined on the table and the call succeeds then it will have a null value.
208+
When the HTTP response cannot be deserialized, then the `http-completion-state` will be `UNABLE_TO_DESERIALIZE_RESPONSE`
209+
and the `error-string` will be the response body. Note that `UNABLE_TO_DESERIALIZE_RESPONSE` is a new enum value added
210+
since [0.22.0], please ensure you amend your applications and SQL appropriately.
207211

208212
When a http lookup call fails and populates the metadata columns with the error information, the expected enrichment columns from the http call
209213
are not populated, this means that they will be null for nullable columns and hold a default value for the type for non-nullable columns.

src/main/java/com/getindata/connectors/http/internal/table/lookup/HttpCompletionState.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
public enum HttpCompletionState {
44
HTTP_ERROR_STATUS,
55
EXCEPTION,
6-
SUCCESS
6+
SUCCESS,
7+
UNABLE_TO_DESERIALIZE_RESPONSE
78
}

src/main/java/com/getindata/connectors/http/internal/table/lookup/JavaNetHttpPollingClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ private HttpRowDataWrapper processHttpResponse(
235235
rowData = deserialize(responseBody);
236236
} catch (IOException e) {
237237
if (!this.continueOnError) throw e;
238-
httpCompletionState = HttpCompletionState.EXCEPTION;
239-
errMessage = e.getMessage();
238+
httpCompletionState = HttpCompletionState.UNABLE_TO_DESERIALIZE_RESPONSE;
239+
errMessage = responseBody;
240240
}
241241
return HttpRowDataWrapper.builder()
242242
.data(rowData)

src/test/java/com/getindata/connectors/http/internal/table/lookup/HttpLookupTableSourceITCaseTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class HttpLookupTableSourceITCaseTest {
7878

7979
return row1Id.compareTo(row2Id);
8080
};
81+
public static final String A_TEST_STRING_THAT_IS_NOT_JSON = "A test string that is not json";
8182

8283
private StreamTableEnvironment tEnv;
8384

@@ -1081,10 +1082,11 @@ private void assertEnrichedRowsDeserException(Collection<Row> collectedRows ) {
10811082
assertThat(row.getField("balance")).isNull();
10821083
// metadata
10831084
assertThat(row.getField("errStr"))
1084-
.isEqualTo("Failed to deserialize JSON 'A test string that is not json'.");
1085+
.isEqualTo(A_TEST_STRING_THAT_IS_NOT_JSON);
10851086
assertThat(row.getField("headers")).isNotNull();
10861087
assertThat(row.getField("statusCode")).isEqualTo(200);
1087-
assertEquals(row.getField("completionState"), HttpCompletionState.EXCEPTION.name());
1088+
assertEquals(row.getField("completionState"), HttpCompletionState.UNABLE_TO_DESERIALIZE_RESPONSE
1089+
.name());
10881090
}
10891091
}
10901092
);
@@ -1393,7 +1395,7 @@ private void setupServerStubForSpec(TestSpec spec) {
13931395
if (StringUtils.isNullOrWhitespaceOnly(spec.methodName) || spec.methodName.equalsIgnoreCase("GET")) {
13941396
wireMockServer.stubFor(get(urlPathEqualTo(ENDPOINT))
13951397
.withHeader("Content-Type", equalTo("application/json"))
1396-
.willReturn(aResponse().withBody("A test string that is not json").withStatus(200))
1398+
.willReturn(aResponse().withBody(A_TEST_STRING_THAT_IS_NOT_JSON).withStatus(200))
13971399
);
13981400
} else {
13991401
setUpServerBodyStub(

0 commit comments

Comments
 (0)