Skip to content

Commit

Permalink
Put ErrorInfo in Status details instead of trailers.
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjayVas committed Jun 5, 2023
1 parent 8c76d38 commit 0feeed2
Show file tree
Hide file tree
Showing 34 changed files with 372 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ class SpannerAccountsService(
)
.execute(client, idGenerator)
} catch (e: AccountNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Creator's Account not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Creator's Account not found.")
} catch (e: PermissionDeniedException) {
e.throwStatusRuntimeException(Status.PERMISSION_DENIED) {
throw e.asStatusRuntimeException(
Status.Code.PERMISSION_DENIED,
"Caller does not own the owned measurement consumer."
}
)
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.")
}
}

Expand All @@ -102,21 +103,27 @@ class SpannerAccountsService(
)
.execute(client, idGenerator)
} catch (e: PermissionDeniedException) {
e.throwStatusRuntimeException(Status.PERMISSION_DENIED) {
throw e.asStatusRuntimeException(
Status.Code.PERMISSION_DENIED,
"Activation token is not valid for this account."
}
)
} catch (e: DuplicateAccountIdentityException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) {
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Issuer and subject pair already exists."
}
)
} catch (e: AccountActivationStateIllegalException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) {
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Cannot activate an account again. "
}
)
} catch (e: AccountNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Account to activate has not been found." }
throw e.asStatusRuntimeException(
Status.Code.NOT_FOUND,
"Account to activate has not been found."
)
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error")
}
}

Expand All @@ -129,17 +136,19 @@ class SpannerAccountsService(
)
.execute(client, idGenerator)
} catch (e: DuplicateAccountIdentityException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) {
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Issuer and subject pair already exists."
}
)
} catch (e: AccountNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Account was not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Account was not found.")
} catch (e: AccountActivationStateIllegalException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) {
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Account has not been activated yet."
}
)
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ class SpannerApiKeysService(
try {
return CreateApiKey(request).execute(client, idGenerator)
} catch (e: MeasurementConsumerNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "MeasurementConsumer not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "MeasurementConsumer not found.")
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error")
}
}

Expand All @@ -54,11 +54,11 @@ class SpannerApiKeysService(
)
.execute(client, idGenerator)
} catch (e: MeasurementConsumerNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "MeasurementConsumer not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "MeasurementConsumer not found.")
} catch (e: ApiKeyNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Api Key not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Api Key not found.")
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,20 @@ class SpannerCertificatesService(
try {
return CreateCertificate(request).execute(client, idGenerator)
} catch (e: MeasurementConsumerNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Measurement Consumer not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Measurement Consumer not found.")
} catch (e: DataProviderNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Data Provider not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Data Provider not found.")
} catch (e: ModelProviderNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Model Provider not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Model Provider not found.")
} catch (e: CertSubjectKeyIdAlreadyExistsException) {
e.throwStatusRuntimeException(Status.ALREADY_EXISTS) {
throw e.asStatusRuntimeException(
Status.Code.ALREADY_EXISTS,
"Certificate with the subject key identifier (SKID) already exists."
}
)
} catch (e: DuchyNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Duchy not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Duchy not found.")
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error")
}
}

Expand Down Expand Up @@ -117,13 +118,16 @@ class SpannerCertificatesService(
try {
return RevokeCertificate(request).execute(client, idGenerator)
} catch (e: CertificateNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Certificate not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Certificate not found.")
} catch (e: DuchyNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Duchy not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Duchy not found.")
} catch (e: CertificateRevocationStateIllegalException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Certificate is in wrong State." }
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Certificate is in wrong State."
)
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error")
}
}

Expand All @@ -134,13 +138,16 @@ class SpannerCertificatesService(
try {
return ReleaseCertificateHold(request).execute(client, idGenerator)
} catch (e: CertificateNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Certificate not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Certificate not found.")
} catch (e: DuchyNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "Duchy not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "Duchy not found.")
} catch (e: CertificateRevocationStateIllegalException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Certificate is in wrong State." }
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Certificate is in wrong State."
)
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,38 @@ class SpannerComputationParticipantsService(
try {
return SetParticipantRequisitionParams(request).execute(client, idGenerator)
} catch (e: ComputationParticipantStateIllegalException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) {
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"ComputationParticipant not in CREATED state."
}
)
} catch (e: MeasurementStateIllegalException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) {
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Measurement not in PENDING_REQUISITION_PARAMS state."
}
)
} catch (e: ComputationParticipantNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "ComputationParticipant not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ComputationParticipant not found.")
} catch (e: DuchyNotFoundException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy not found." }
throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.")
} catch (e: DuchyCertificateNotFoundException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy's Certificate not found." }
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Duchy's Certificate not found."
)
} catch (e: CertificateIsInvalidException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Certificate is invalid." }
throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Certificate is invalid.")
} catch (e: DuplicateAccountIdentityException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Account Identity duplicated." }
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Account Identity duplicated."
)
} catch (e: AccountActivationStateIllegalException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) {
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Account activation state illegal."
}
)
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.")
}
}

Expand All @@ -77,13 +86,16 @@ class SpannerComputationParticipantsService(
try {
return FailComputationParticipant(request).execute(client, idGenerator)
} catch (e: ComputationParticipantNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "ComputationParticipant not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ComputationParticipant not found.")
} catch (e: DuchyNotFoundException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy not found." }
throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.")
} catch (e: MeasurementStateIllegalException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Measurement state is illegal." }
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Measurement state is illegal."
)
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.")
}
}

Expand All @@ -93,17 +105,21 @@ class SpannerComputationParticipantsService(
try {
return ConfirmComputationParticipant(request).execute(client, idGenerator)
} catch (e: ComputationParticipantNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "ComputationParticipant not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "ComputationParticipant not found.")
} catch (e: ComputationParticipantStateIllegalException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) {
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"ComputationParticipant in illegal state."
}
)
} catch (e: DuchyNotFoundException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Duchy not found." }
throw e.asStatusRuntimeException(Status.Code.FAILED_PRECONDITION, "Duchy not found.")
} catch (e: MeasurementStateIllegalException) {
e.throwStatusRuntimeException(Status.FAILED_PRECONDITION) { "Measurement in illegal state." }
throw e.asStatusRuntimeException(
Status.Code.FAILED_PRECONDITION,
"Measurement in illegal state."
)
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error." }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SpannerDataProvidersService(
try {
return ReplaceDataProviderRequiredDuchies(request).execute(client, idGenerator)
} catch (e: DataProviderNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "DataProvider not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "DataProvider not found.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ class SpannerEventGroupMetadataDescriptorsService(
try {
return CreateEventGroupMetadataDescriptor(request).execute(client, idGenerator)
} catch (e: DataProviderNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "DataProvider not found." }
throw e.asStatusRuntimeException(Status.Code.NOT_FOUND, "DataProvider not found.")
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error")
}
}

Expand Down Expand Up @@ -76,9 +76,12 @@ class SpannerEventGroupMetadataDescriptorsService(
return UpdateEventGroupMetadataDescriptor(request.eventGroupMetadataDescriptor)
.execute(client, idGenerator)
} catch (e: EventGroupMetadataDescriptorNotFoundException) {
e.throwStatusRuntimeException(Status.NOT_FOUND) { "EventGroupMetadataDescriptor not found." }
throw e.asStatusRuntimeException(
Status.Code.NOT_FOUND,
"EventGroupMetadataDescriptor not found."
)
} catch (e: KingdomInternalException) {
e.throwStatusRuntimeException(Status.INTERNAL) { "Unexpected internal error" }
throw e.asStatusRuntimeException(Status.Code.INTERNAL, "Unexpected internal error")
}
}

Expand Down
Loading

0 comments on commit 0feeed2

Please sign in to comment.