Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import com.google.api.client.http.HttpResponseException;
import com.google.api.core.BetaApi;
import com.google.api.core.InternalApi;
import com.google.api.gax.grpc.GrpcApiException;
import com.google.api.gax.grpc.GrpcStatusCode;
import com.google.api.gax.rpc.ApiException;
import com.google.cloud.BaseServiceException;
import com.google.common.base.MoreObjects;
import java.io.IOException;
Expand Down Expand Up @@ -66,13 +67,13 @@ private static ExceptionData makeExceptionData(IOException exception, boolean id
}

@BetaApi
public BaseGrpcServiceException(GrpcApiException apiException) {
public BaseGrpcServiceException(ApiException apiException) {
super(ExceptionData.newBuilder()
.setMessage(apiException.getMessage())
.setCause(apiException)
.setRetryable(apiException.isRetryable())
.setCode(apiException.getStatusCode().getCode().value())
.setReason(apiException.getStatusCode().getCode().name())
.setCode(((GrpcStatusCode) apiException.getStatusCode()).getCode().value())
.setReason(((GrpcStatusCode) apiException.getStatusCode()).getCode().name())
.setLocation(null)
.setDebugInfo(null)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import com.google.api.gax.grpc.GrpcApiException;
import com.google.api.gax.grpc.GrpcStatusCode;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.InternalException;
import com.google.cloud.BaseServiceException;
import com.google.cloud.RetryHelper;
import io.grpc.Status.Code;
Expand Down Expand Up @@ -73,8 +75,8 @@ public void testBaseServiceException() {
assertNull(serviceException.getDebugInfo());

Exception cause = new IllegalArgumentException("bad arg");
GrpcApiException apiException =
new GrpcApiException(MESSAGE, cause, Code.INTERNAL, NOT_RETRYABLE);
InternalException apiException =
new InternalException(MESSAGE, cause, GrpcStatusCode.of(Code.INTERNAL), NOT_RETRYABLE);
serviceException = new BaseGrpcServiceException(apiException);
assertFalse(serviceException.isRetryable());
assertEquals(MESSAGE, serviceException.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
package com.google.cloud.dlp.v2beta1;

import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GrpcApiException;
import com.google.api.gax.grpc.GrpcStatusCode;
import com.google.api.gax.grpc.GrpcTransportProvider;
import com.google.api.gax.grpc.testing.MockGrpcService;
import com.google.api.gax.grpc.testing.MockServiceHelper;
import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.longrunning.Operation;
import com.google.privacy.dlp.v2beta1.ContentItem;
import com.google.privacy.dlp.v2beta1.CreateInspectOperationRequest;
Expand Down Expand Up @@ -125,8 +126,8 @@ public void inspectContentExceptionTest() throws Exception {

client.inspectContent(inspectConfig, items);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -166,8 +167,8 @@ public void redactContentExceptionTest() throws Exception {

client.redactContent(inspectConfig, items, replaceConfigs);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -217,10 +218,11 @@ public void createInspectOperationExceptionTest() throws Exception {
client.createInspectOperationAsync(inspectConfig, storageConfig, outputConfig).get();
Assert.fail("No exception raised");
} catch (ExecutionException e) {
Assert.assertEquals(GrpcApiException.class, e.getCause().getClass());
GrpcApiException apiException = (GrpcApiException) e.getCause();
Assert.assertEquals(InvalidArgumentException.class, e.getCause().getClass());
InvalidArgumentException apiException = (InvalidArgumentException) e.getCause();
Assert.assertEquals(
Status.INVALID_ARGUMENT.getCode(), apiException.getStatusCode().getCode());
Status.INVALID_ARGUMENT.getCode(),
((GrpcStatusCode) apiException.getStatusCode()).getCode());
}
}

Expand Down Expand Up @@ -255,8 +257,8 @@ public void listInspectFindingsExceptionTest() throws Exception {

client.listInspectFindings(name);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -292,8 +294,8 @@ public void listInfoTypesExceptionTest() throws Exception {

client.listInfoTypes(category, languageCode);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -326,8 +328,8 @@ public void listRootCategoriesExceptionTest() throws Exception {

client.listRootCategories(languageCode);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package com.google.cloud.errorreporting.v1beta1;

import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GrpcApiException;
import com.google.api.gax.grpc.GrpcTransportProvider;
import com.google.api.gax.grpc.testing.MockGrpcService;
import com.google.api.gax.grpc.testing.MockServiceHelper;
import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.devtools.clouderrorreporting.v1beta1.ErrorGroup;
import com.google.devtools.clouderrorreporting.v1beta1.GetGroupRequest;
import com.google.devtools.clouderrorreporting.v1beta1.GroupName;
Expand Down Expand Up @@ -114,8 +114,8 @@ public void getGroupExceptionTest() throws Exception {

client.getGroup(groupName);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -151,8 +151,8 @@ public void updateGroupExceptionTest() throws Exception {

client.updateGroup(group);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
import static com.google.cloud.errorreporting.v1beta1.PagedResponseWrappers.ListGroupStatsPagedResponse;

import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GrpcApiException;
import com.google.api.gax.grpc.GrpcTransportProvider;
import com.google.api.gax.grpc.testing.MockGrpcService;
import com.google.api.gax.grpc.testing.MockServiceHelper;
import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.common.collect.Lists;
import com.google.devtools.clouderrorreporting.v1beta1.DeleteEventsRequest;
import com.google.devtools.clouderrorreporting.v1beta1.DeleteEventsResponse;
Expand Down Expand Up @@ -134,8 +134,8 @@ public void listGroupStatsExceptionTest() throws Exception {

client.listGroupStats(projectName, timeRange);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -181,8 +181,8 @@ public void listEventsExceptionTest() throws Exception {

client.listEvents(projectName, groupId);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -215,8 +215,8 @@ public void deleteEventsExceptionTest() throws Exception {

client.deleteEvents(projectName);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package com.google.cloud.errorreporting.v1beta1;

import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GrpcApiException;
import com.google.api.gax.grpc.GrpcTransportProvider;
import com.google.api.gax.grpc.testing.MockGrpcService;
import com.google.api.gax.grpc.testing.MockServiceHelper;
import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.devtools.clouderrorreporting.v1beta1.ProjectName;
import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventRequest;
import com.google.devtools.clouderrorreporting.v1beta1.ReportErrorEventResponse;
Expand Down Expand Up @@ -114,8 +114,8 @@ public void reportErrorEventExceptionTest() throws Exception {

client.reportErrorEvent(projectName, event);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.google.api.gax.grpc.GrpcApiException;
import com.google.api.gax.rpc.ApiException;
import com.google.cloud.Identity;
import com.google.cloud.Role;
import com.google.cloud.pubsub.v1.PagedResponseWrappers.ListSubscriptionsPagedResponse;
Expand Down Expand Up @@ -124,7 +124,7 @@ public void listSubscriptionsRetrievesAllAddedSubscriptions() throws Exception {
assertTrue(subFound[0] && subFound[1]);
}

@Test(expected = GrpcApiException.class)
@Test(expected = ApiException.class)
public void deleteSubscriptionThrowsExceptionWhenRetrieved() throws Exception {
String topicName = topics[0];
String subscriptionName = subscriptions[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import com.google.api.gax.grpc.GrpcApiException;
import com.google.api.gax.rpc.ApiException;
import com.google.cloud.Identity;
import com.google.cloud.Role;
import com.google.cloud.pubsub.v1.PagedResponseWrappers.ListTopicSubscriptionsPagedResponse;
Expand Down Expand Up @@ -136,7 +136,7 @@ public void listTopicSubscriptionsRetrievesAddedSubscriptions() throws Exception
assertTrue(subFound[0] && subFound[1]);
}

@Test(expected = GrpcApiException.class)
@Test(expected = ApiException.class)
public void deletedTopicIsNotRetrievableAndThrowsException() throws Exception {
String topicName = topics[0];
Topic topicAdded = topicAdminClientSnippets.createTopic(topicName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package com.google.cloud.language.v1;

import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GrpcApiException;
import com.google.api.gax.grpc.GrpcTransportProvider;
import com.google.api.gax.grpc.testing.MockGrpcService;
import com.google.api.gax.grpc.testing.MockServiceHelper;
import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.cloud.language.v1.AnnotateTextRequest.Features;
import com.google.protobuf.GeneratedMessageV3;
import io.grpc.Status;
Expand Down Expand Up @@ -103,8 +103,8 @@ public void analyzeSentimentExceptionTest() throws Exception {

client.analyzeSentiment(document);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -142,8 +142,8 @@ public void analyzeEntitiesExceptionTest() throws Exception {

client.analyzeEntities(document, encodingType);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -181,8 +181,8 @@ public void analyzeSyntaxExceptionTest() throws Exception {

client.analyzeSyntax(document, encodingType);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -223,8 +223,8 @@ public void annotateTextExceptionTest() throws Exception {

client.annotateText(document, features, encodingType);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
package com.google.cloud.language.v1beta2;

import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GrpcApiException;
import com.google.api.gax.grpc.GrpcTransportProvider;
import com.google.api.gax.grpc.testing.MockGrpcService;
import com.google.api.gax.grpc.testing.MockServiceHelper;
import com.google.api.gax.rpc.InvalidArgumentException;
import com.google.cloud.language.v1beta2.AnnotateTextRequest.Features;
import com.google.protobuf.GeneratedMessageV3;
import io.grpc.Status;
Expand Down Expand Up @@ -103,8 +103,8 @@ public void analyzeSentimentExceptionTest() throws Exception {

client.analyzeSentiment(document);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -142,8 +142,8 @@ public void analyzeEntitiesExceptionTest() throws Exception {

client.analyzeEntities(document, encodingType);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -183,8 +183,8 @@ public void analyzeEntitySentimentExceptionTest() throws Exception {

client.analyzeEntitySentiment(document, encodingType);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -222,8 +222,8 @@ public void analyzeSyntaxExceptionTest() throws Exception {

client.analyzeSyntax(document, encodingType);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}

Expand Down Expand Up @@ -264,8 +264,8 @@ public void annotateTextExceptionTest() throws Exception {

client.annotateText(document, features, encodingType);
Assert.fail("No exception raised");
} catch (GrpcApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode().getCode());
} catch (InvalidArgumentException e) {
// Expected exception
}
}
}
Loading