Pārlūkot izejas kodu

Clean up nested condition

Mauricio Araujo 2 gadi atpakaļ
vecāks
revīzija
44d1655a6f
1 mainītis faili ar 6 papildinājumiem un 5 dzēšanām
  1. 6 5
      internal/billing/usage.go

+ 6 - 5
internal/billing/usage.go

@@ -380,13 +380,14 @@ func (m LagoClient) IngestEvents(ctx context.Context, subscriptionID string, eve
 		batch := events[i:end]
 		batch := events[i:end]
 		var batchInput []lago.EventInput
 		var batchInput []lago.EventInput
 		for i := range batch {
 		for i := range batch {
+			projectID, err := strconv.ParseUint(batch[i].CustomerID, 10, 64)
+			if err != nil {
+				return telemetry.Error(ctx, span, err, "failed to parse project id")
+			}
+
 			if enableSandbox {
 			if enableSandbox {
 				// For Porter Cloud, we can't infer the project ID from the request, so we
 				// For Porter Cloud, we can't infer the project ID from the request, so we
-				// instead extract it from the billing events
-				projectID, err := strconv.ParseUint(batch[i].CustomerID, 10, 64)
-				if err != nil {
-					return telemetry.Error(ctx, span, err, "failed to parse project id")
-				}
+				// instead use the one in the billing event
 				subscriptionID = m.generateLagoID(SubscriptionIDPrefix, uint(projectID), enableSandbox)
 				subscriptionID = m.generateLagoID(SubscriptionIDPrefix, uint(projectID), enableSandbox)
 			}
 			}