{"record":{"id":"89bc3287b9039175","repo":"fullstackhero/dotnet-starter-kit","slug":"storage-quota-exceeded-check-currentusage-check-limit-bytes","errorCode":null,"errorMessage":"Storage quota exceeded ({check.CurrentUsage}/{check.Limit} bytes).","messagePattern":"Storage quota exceeded \\((.+?)/(.+?) bytes\\)\\.","errorType":"exception","errorClass":"CustomException","httpStatus":507,"severity":"error","filePath":"src/BuildingBlocks/Storage/QuotaMeteredStorageService.cs","lineNumber":69,"sourceCode":"        {\n            return await _inner.UploadAsync<T>(request, fileType, cancellationToken).ConfigureAwait(false);\n        }\n\n        var bytes = request.Data.Count;\n        var check = await _quotas\n            .CheckAndRecordAsync(tenantId, QuotaResource.StorageBytes, bytes, cancellationToken)\n            .ConfigureAwait(false);\n\n        if (!check.Allowed)\n        {\n            if (_logger.IsEnabled(LogLevel.Warning))\n            {\n                _logger.LogWarning(\n                    \"Rejected upload for tenant {TenantId} — storage quota exceeded ({Current}/{Limit} bytes)\",\n                    tenantId, check.CurrentUsage, check.Limit);\n            }\n\n            throw new CustomException(\n                $\"Storage quota exceeded ({check.CurrentUsage}/{check.Limit} bytes).\",\n                errors: null,\n                HttpStatusCode.InsufficientStorage);\n        }\n\n        try\n        {\n            return await _inner.UploadAsync<T>(request, fileType, cancellationToken).ConfigureAwait(false);\n        }\n        catch\n        {\n            // Roll the charge back so a failed write doesn't permanently consume quota.\n            await _quotas\n                .RecordAsync(tenantId, QuotaResource.StorageBytes, -bytes, CancellationToken.None)\n                .ConfigureAwait(false);\n            throw;\n        }\n    }","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/fullstackhero/dotnet-starter-kit/blob/3f2959e683e9f83f13e55e1678c9119f63c7e8e5/src/BuildingBlocks/Storage/QuotaMeteredStorageService.cs#L51-L87","documentation":"QuotaMeteredStorageService.UploadAsync checks the tenant's current storage usage against its configured limit before writing a blob. When the post-upload usage would exceed the limit, it throws CustomException with HTTP 507 (InsufficientStorage). This is an intentional quota guard, not a bug — the tenant has filled its allocated storage.","triggerScenarios":"Calling UploadAsync when check.CurrentUsage + request payload size exceeds the tenant's configured byte limit. Common with the default quota on new tenants, or after bulk uploads.","commonSituations":"Production tenants uploading large media; staging tenants importing demo datasets that exceed default limits; quota limit configured too low in tenant settings; files never deleted so usage ratchets up over time.","solutions":["Increase the tenant's storage limit (quota configuration) if the allocation is too small.","Free space by deleting unused files for that tenant, then retry the upload.","Handle the 507 status client-side and surface a 'storage full' message prompting cleanup or an upgrade.","Enable size pre-checks client-side: reject files before upload when remaining quota is insufficient."],"exampleFix":"// before: blind upload\ncollection.Add(file);\nawait storage.UploadAsync(request);\n\n// after: pre-check quota client-side\nvar check = await quotaClient.CheckAsync(tenantId);\nif (check.CurrentUsage + file.Length > check.Limit)\n    return Results.StatusCode(507); // or trim / upgrade quota","handlingStrategy":"try-catch","validationCode":"var check = await quotaService.GetCurrentUsageAsync(tenantId);\nif (check.CurrentUsage + file.Length >= check.Limit)\n    throw new InvalidOperationException(\"Upload would exceed tenant storage quota.\");","typeGuard":"bool HasQuotaRoom(QuotaCheck c, long incomingBytes) => c.CurrentUsage + incomingBytes < c.Limit;","tryCatchPattern":"try {\n    await storage.UploadAsync(request);\n} catch (CustomException ex) when ((int)ex.StatusCode == 507) {\n    // inform user storage is full; offer cleanup or quota increase\n}","preventionTips":["Show remaining quota in the UI and block uploads that would exceed it.","Alert tenants at 80–90% usage.","Periodically clean orphaned blobs and recompute usage."],"tags":["storage","quota","multitenancy","http-507"],"backgroundTag":"quota-limit-exceeded","analyzedSha":"3f2959e683e9f83f13e55e1678c9119f63c7e8e5","analyzedAt":"2026-09-15T22:20:53.684Z","contentChangedAt":"2026-09-15T22:20:53.684Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}