Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/com/skyflow/errors/SkyflowException.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public SkyflowException(String message, Throwable cause) {
super(message, cause);
this.message = message;
}
public SkyflowException(String message, Throwable cause, int httpCode) {
super(message, cause);
this.message = message;
this.httpCode = httpCode;
}

public SkyflowException(int code, String message) {
super(message);
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/com/skyflow/vault/controller/DetectController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.skyflow.errors.ErrorMessage;
import com.skyflow.errors.SkyflowException;
import com.skyflow.generated.rest.core.ApiClientApiException;
import com.skyflow.generated.rest.core.ApiClientException;
import com.skyflow.generated.rest.core.RequestOptions;
import com.skyflow.generated.rest.resources.files.requests.*;
import com.skyflow.generated.rest.resources.strings.requests.DeidentifyStringRequest;
Expand Down Expand Up @@ -66,6 +67,9 @@ public DeidentifyTextResponse deidentifyText(DeidentifyTextRequest deidentifyTex
String bodyString = extractBodyAsString(ex);
LogUtil.printErrorLog(ErrorLogs.DEIDENTIFY_TEXT_REQUEST_REJECTED.getLog());
throw new SkyflowException(ex.statusCode(), ex, ex.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.DEIDENTIFY_TEXT_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
}
LogUtil.printInfoLog(InfoLogs.DEIDENTIFY_TEXT_SUCCESS.getLog());
return deidentifyTextResponse;
Expand Down Expand Up @@ -94,6 +98,9 @@ public ReidentifyTextResponse reidentifyText(ReidentifyTextRequest reidentifyTex
String bodyString = extractBodyAsString(ex);
LogUtil.printErrorLog(ErrorLogs.REIDENTIFY_TEXT_REQUEST_REJECTED.getLog());
throw new SkyflowException(ex.statusCode(), ex, ex.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.REIDENTIFY_TEXT_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
}
LogUtil.printInfoLog(InfoLogs.REIDENTIFY_TEXT_SUCCESS.getLog());
return reidentifyTextResponse;
Expand Down Expand Up @@ -180,6 +187,9 @@ public DeidentifyFileResponse deidentifyFile(DeidentifyFileRequest request) thro
String bodyString = extractBodyAsString(e);
LogUtil.printErrorLog(ErrorLogs.DEIDENTIFY_FILE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.DEIDENTIFY_FILE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
}
return response;
}
Expand Down Expand Up @@ -431,6 +441,9 @@ public DeidentifyFileResponse getDetectRun(GetDetectRunRequest request) throws S
String bodyString = extractBodyAsString(e);
LogUtil.printErrorLog(ErrorLogs.GET_DETECT_RUN_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.GET_DETECT_RUN_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
}
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/skyflow/vault/controller/VaultController.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.skyflow.errors.ErrorCode;
import com.skyflow.errors.SkyflowException;
import com.skyflow.generated.rest.core.ApiClientApiException;
import com.skyflow.generated.rest.core.ApiClientException;
import com.skyflow.generated.rest.core.ApiClientHttpResponse;
import com.skyflow.generated.rest.core.RequestOptions;
import com.skyflow.generated.rest.resources.query.requests.QueryServiceExecuteQueryBody;
Expand Down Expand Up @@ -202,6 +203,9 @@ public InsertResponse insert(InsertRequest insertRequest) throws SkyflowExceptio
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.INSERT_RECORDS_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.INSERT_RECORDS_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
}
LogUtil.printInfoLog(InfoLogs.INSERT_SUCCESS.getLog());
if (insertedFields.isEmpty()) {
Expand Down Expand Up @@ -247,6 +251,9 @@ public DetokenizeResponse detokenize(DetokenizeRequest detokenizeRequest) throws
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.DETOKENIZE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.DETOKENIZE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
}

if (!errorRecords.isEmpty()) {
Expand Down Expand Up @@ -304,6 +311,9 @@ public GetResponse get(GetRequest getRequest) throws SkyflowException {
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.GET_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.GET_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
}
LogUtil.printInfoLog(InfoLogs.GET_SUCCESS.getLog());
return new GetResponse(data, null);
Expand Down Expand Up @@ -334,6 +344,9 @@ public UpdateResponse update(UpdateRequest updateRequest) throws SkyflowExceptio
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.UPDATE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.UPDATE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
}
LogUtil.printInfoLog(InfoLogs.UPDATE_SUCCESS.getLog());
return new UpdateResponse(skyflowId, tokensMap);
Expand All @@ -357,6 +370,9 @@ public DeleteResponse delete(DeleteRequest deleteRequest) throws SkyflowExceptio
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.DELETE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.DELETE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
}
LogUtil.printInfoLog(InfoLogs.DELETE_SUCCESS.getLog());
return new DeleteResponse(result.getRecordIdResponse().get());
Expand Down Expand Up @@ -387,6 +403,9 @@ public QueryResponse query(QueryRequest queryRequest) throws SkyflowException {
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.QUERY_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.QUERY_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
}
LogUtil.printInfoLog(InfoLogs.QUERY_SUCCESS.getLog());
return new QueryResponse(fields);
Expand Down Expand Up @@ -415,6 +434,9 @@ public TokenizeResponse tokenize(TokenizeRequest tokenizeRequest) throws Skyflow
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.TOKENIZE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.TOKENIZE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
}
LogUtil.printInfoLog(InfoLogs.TOKENIZE_SUCCESS.getLog());
return new TokenizeResponse(list);
Expand Down Expand Up @@ -454,6 +476,9 @@ public FileUploadResponse uploadFile(FileUploadRequest fileUploadRequest) throws
String bodyString = GSON.toJson(e.body());
LogUtil.printErrorLog(ErrorLogs.UPLOAD_FILE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.statusCode(), e, e.headers(), bodyString);
} catch (ApiClientException e) {
LogUtil.printErrorLog(ErrorLogs.UPLOAD_FILE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e.getCause(), ErrorCode.INVALID_INPUT.getCode());
} catch (IOException e) {
LogUtil.printErrorLog(ErrorLogs.UPLOAD_FILE_REQUEST_REJECTED.getLog());
throw new SkyflowException(e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,4 +406,36 @@ public void testOutputDirectoryNotWritable() throws Exception {
dir.delete();
}
}

@Test
public void testApiClientExceptionInDeidentifyFileMethod() throws Exception {
try {
File file = File.createTempFile("test", ".txt");
FileInput fileInput = FileInput.builder().file(file).build();
DeidentifyFileRequest request = DeidentifyFileRequest.builder().file(fileInput).waitTime(1).build();
detectController.deidentifyFile(request);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals("Network error executing HTTP request", e.getMessage());
Assert.assertNull(e.getRequestId());
Assert.assertNull(e.getGrpcCode());
Assert.assertNull(e.getDetails());
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
}
}

@Test
public void testApiClientExceptionInGetDetectRunMethod() {
try {
GetDetectRunRequest request = GetDetectRunRequest.builder().runId("dummy-run-id").build();
detectController.getDetectRun(request);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals("Network error executing HTTP request", e.getMessage());
Assert.assertNull(e.getRequestId());
Assert.assertNull(e.getGrpcCode());
Assert.assertNull(e.getDetails());
Assert.assertEquals(ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,36 @@ public void testEmptyTextInRequestInReidentifyStringMethod() {
}
}

}
@Test
public void testApiClientExceptionInDeidentifyTextMethod() {
try {
DeidentifyTextRequest request = DeidentifyTextRequest.builder().text("Sensitive text").build();
skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addVaultConfig(vaultConfig).build();
skyflowClient.detect(vaultID).deidentifyText(request);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals("Network error executing HTTP request", e.getMessage());
Assert.assertNull(e.getRequestId());
Assert.assertNull(e.getGrpcCode());
Assert.assertNull(e.getDetails());
Assert.assertEquals(com.skyflow.errors.ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
}
}

@Test
public void testApiClientExceptionInReidentifyTextMethod() {
try {
ReidentifyTextRequest request = ReidentifyTextRequest.builder().text("Deidentified text").build();
skyflowClient = Skyflow.builder().setLogLevel(LogLevel.DEBUG).addVaultConfig(vaultConfig).build();
skyflowClient.detect(vaultID).reidentifyText(request);
Assert.fail(EXCEPTION_NOT_THROWN);
} catch (SkyflowException e) {
Assert.assertEquals("Network error executing HTTP request", e.getMessage());
Assert.assertNull(e.getRequestId());
Assert.assertNull(e.getGrpcCode());
Assert.assertNull(e.getDetails());
Assert.assertEquals(com.skyflow.errors.ErrorCode.INVALID_INPUT.getCode(), e.getHttpCode());
}
}

}
Loading
Loading