Skip to content

Commit 5a8bf5a

Browse files
committed
fix: Don't panic if the server returns 0 as the quota limit
1 parent 37ebc2c commit 5a8bf5a

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/types/quota.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ impl From<QuotaResourceRef<'_>> for QuotaResource {
4848
impl QuotaResource {
4949
/// Returns the usage percentage of a QuotaResource.
5050
pub fn get_usage_percentage(&self) -> u64 {
51-
self.usage.saturating_mul(100) / self.limit
51+
self.usage
52+
.saturating_mul(100)
53+
.checked_div(self.limit)
54+
// Assume that if `limit` is 0, this means that storage is unlimited:
55+
.unwrap_or(0)
5256
}
5357
}
5458

0 commit comments

Comments
 (0)