diff --git a/samples/snippets/src/main/java/pubsub/CommitAvroSchemaExample.java b/samples/snippets/src/main/java/pubsub/CommitAvroSchemaExample.java index e6ac8f278..8f24e75a2 100644 --- a/samples/snippets/src/main/java/pubsub/CommitAvroSchemaExample.java +++ b/samples/snippets/src/main/java/pubsub/CommitAvroSchemaExample.java @@ -18,7 +18,7 @@ // [START pubsub_commit_avro_schema] -import com.google.api.gax.rpc.AlreadyExistsException; +import com.google.api.gax.rpc.NotFoundException; import com.google.cloud.pubsub.v1.SchemaServiceClient; import com.google.pubsub.v1.ProjectName; import com.google.pubsub.v1.Schema; @@ -60,8 +60,8 @@ public static Schema commitAvroSchemaExample(String projectId, String schemaId, System.out.println("Committed a schema using an Avro schema:\n" + schema); return schema; - } catch (AlreadyExistsException e) { - System.out.println(schemaName + "already exists."); + } catch (NotFoundException e) { + System.out.println(schemaName + "does not exist."); return null; } } diff --git a/samples/snippets/src/main/java/pubsub/CommitProtoSchemaExample.java b/samples/snippets/src/main/java/pubsub/CommitProtoSchemaExample.java index b32de29dc..e609b9a5f 100644 --- a/samples/snippets/src/main/java/pubsub/CommitProtoSchemaExample.java +++ b/samples/snippets/src/main/java/pubsub/CommitProtoSchemaExample.java @@ -18,7 +18,7 @@ // [START pubsub_commit_proto_schema] -import com.google.api.gax.rpc.AlreadyExistsException; +import com.google.api.gax.rpc.NotFoundException; import com.google.cloud.pubsub.v1.SchemaServiceClient; import com.google.pubsub.v1.ProjectName; import com.google.pubsub.v1.Schema; @@ -60,8 +60,8 @@ public static Schema commitProtoSchemaExample(String projectId, String schemaId, System.out.println("Committed a schema using a protobuf schema:\n" + schema); return schema; - } catch (AlreadyExistsException e) { - System.out.println(schemaName + "already exists."); + } catch (NotFoundException e) { + System.out.println(schemaName + "does not exist."); return null; } }