Skip to content

Commit

Permalink
Connector builder: Throw 422 if requests are missing a field (#5955)
Browse files Browse the repository at this point in the history
  • Loading branch information
girarda committed Apr 20, 2023
1 parent 0b0081e commit 95f25ae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public AirbyteCdkRequesterImpl(final SynchronousCdkCommandRunner commandRunner)
public StreamRead readStream(final JsonNode manifest, final JsonNode config, final String stream, final Integer recordLimit)
throws IOException, AirbyteCdkInvalidInputException, CdkProcessException {
if (stream == null) {
throw new CdkProcessException("Missing required `stream` field.");
throw new AirbyteCdkInvalidInputException("Missing required `stream` field.");
}
final AirbyteRecordMessage record = request(manifest, config, readStreamCommand, stream, recordLimit);
final StreamRead response = new StreamRead();
Expand Down Expand Up @@ -104,12 +104,12 @@ public StreamsListRead listStreams(final JsonNode manifest, final JsonNode confi

private StreamsListReadStreamsInner adaptStream(final JsonNode stream) {
if (isNull(stream, "name")) {
throw new CdkProcessException(String.format(
throw new AirbyteCdkInvalidInputException(String.format(
"Unexpected fatal error: streams are expected to have field 'name' but could not find it in %s. Please open a GitHub issue with Airbyte",
stream));
}
if (isNull(stream, "url")) {
throw new CdkProcessException(String.format(
throw new AirbyteCdkInvalidInputException(String.format(
"Unexpected fatal error: streams are expected to have field 'url' but could not find it in %s. Please open a GitHub issue with Airbyte",
stream));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import io.airbyte.connector_builder.api.model.generated.StreamsListRead;
import io.airbyte.connector_builder.api.model.generated.StreamsListReadStreamsInner;
import io.airbyte.connector_builder.command_runner.SynchronousCdkCommandRunner;
import io.airbyte.connector_builder.exceptions.CdkProcessException;
import io.airbyte.connector_builder.exceptions.AirbyteCdkInvalidInputException;
import io.airbyte.protocol.models.AirbyteRecordMessage;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -78,14 +78,14 @@ void whenListStreamsThenReturnAdaptedCommandRunnerResponse() throws Exception {
void givenNameIsNullWhenListStreamsThenThrowException() throws Exception {
when(commandRunner.runCommand(eq(LIST_STREAMS_COMMAND), any(), any()))
.thenReturn(new AirbyteRecordMessage().withData(new ObjectMapper().readTree("{\"streams\":[{\"url\": \"missing name\"}]}")));
assertThrows(CdkProcessException.class, () -> requester.listStreams(A_MANIFEST, A_CONFIG));
assertThrows(AirbyteCdkInvalidInputException.class, () -> requester.listStreams(A_MANIFEST, A_CONFIG));
}

@Test
void givenUrlIsNullWhenListStreamsThenThrowException() throws Exception {
when(commandRunner.runCommand(eq(LIST_STREAMS_COMMAND), any(), any()))
.thenReturn(new AirbyteRecordMessage().withData(new ObjectMapper().readTree("{\"streams\":[{\"name\": \"missing url\", \"url\": null}]}")));
assertThrows(CdkProcessException.class, () -> requester.listStreams(A_MANIFEST, A_CONFIG));
assertThrows(AirbyteCdkInvalidInputException.class, () -> requester.listStreams(A_MANIFEST, A_CONFIG));
}

ArgumentCaptor<String> testReadStreamSuccess(final Integer limit) throws Exception {
Expand Down Expand Up @@ -136,7 +136,7 @@ void givenStreamIsNullWhenReadStreamThenThrowException() throws Exception {
when(commandRunner.runCommand(eq(READ_STREAM_COMMAND), any(), any()))
.thenReturn(
new AirbyteRecordMessage().withData(new ObjectMapper().readTree("{\"streams\":[{\"name\": \"missing stream\", \"stream\": null}]}")));
assertThrows(CdkProcessException.class, () -> requester.readStream(A_MANIFEST, A_CONFIG, null, A_LIMIT));
assertThrows(AirbyteCdkInvalidInputException.class, () -> requester.readStream(A_MANIFEST, A_CONFIG, null, A_LIMIT));
}

void assertRunCommandArgs(final ArgumentCaptor<String> configCaptor, final String command) throws Exception {
Expand Down

0 comments on commit 95f25ae

Please sign in to comment.