Skip to content

Commit

Permalink
Detail the error types in createMetric and batchCreateMetrics. (#1005)
Browse files Browse the repository at this point in the history
  • Loading branch information
riemanli authored May 18, 2023
1 parent 1834763 commit ba15186
Showing 1 changed file with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,20 @@ class MetricsService(
try {
internalMetricsStub.createMetric(internalCreateMetricRequest)
} catch (e: StatusException) {
throw Exception("Unable to create the metric in the reporting database.", e)
throw when (e.status.code) {
Status.Code.NOT_FOUND ->
Status.NOT_FOUND.withDescription("Reporting set used in the metric not found.")
Status.Code.FAILED_PRECONDITION ->
Status.FAILED_PRECONDITION.withDescription(
"Unable to create the metric. The measurement consumer not found."
)
else ->
Status.UNKNOWN.withDescription(
"Unable to create the metric in the reporting database."
)
}
.withCause(e)
.asRuntimeException()
}

if (internalMetric.state == Metric.State.RUNNING) {
Expand Down Expand Up @@ -1227,7 +1240,18 @@ class MetricsService(
.metricsList
.filter { internalMetric -> internalMetric.state == Metric.State.RUNNING }
} catch (e: StatusException) {
throw Exception("Unable to create the metric in the reporting database.", e)
throw when (e.status.code) {
Status.Code.NOT_FOUND ->
Status.NOT_FOUND.withDescription("Reporting set used in metrics not found.")
Status.Code.FAILED_PRECONDITION ->
Status.FAILED_PRECONDITION.withDescription(
"Unable to create the metrics. The measurement consumer not found."
)
else ->
Status.UNKNOWN.withDescription("Unable to create metrics in the reporting database.")
}
.withCause(e)
.asRuntimeException()
}

measurementSupplier.createCmmsMeasurements(internalMetrics, principal)
Expand Down

0 comments on commit ba15186

Please sign in to comment.