Fix crash when extra_usage fields are null
This commit is contained in:
@@ -83,10 +83,10 @@ struct UsageWindow: Codable {
|
||||
|
||||
struct ExtraUsage: Codable {
|
||||
let isEnabled: Bool
|
||||
let monthlyLimit: Double
|
||||
let usedCredits: Double
|
||||
let utilization: Double
|
||||
let currency: String
|
||||
let monthlyLimit: Double?
|
||||
let usedCredits: Double?
|
||||
let utilization: Double?
|
||||
let currency: String?
|
||||
enum CodingKeys: String, CodingKey {
|
||||
case isEnabled = "is_enabled"
|
||||
case monthlyLimit = "monthly_limit"
|
||||
@@ -94,6 +94,14 @@ struct ExtraUsage: Codable {
|
||||
case utilization
|
||||
case currency
|
||||
}
|
||||
init(from decoder: Decoder) throws {
|
||||
let c = try decoder.container(keyedBy: CodingKeys.self)
|
||||
isEnabled = (try? c.decodeIfPresent(Bool.self, forKey: .isEnabled)) ?? false
|
||||
monthlyLimit = try? c.decodeIfPresent(Double.self, forKey: .monthlyLimit)
|
||||
usedCredits = try? c.decodeIfPresent(Double.self, forKey: .usedCredits)
|
||||
utilization = try? c.decodeIfPresent(Double.self, forKey: .utilization)
|
||||
currency = try? c.decodeIfPresent(String.self, forKey: .currency)
|
||||
}
|
||||
}
|
||||
|
||||
// (Bootstrap models removed — org ID is configured directly)
|
||||
|
||||
Reference in New Issue
Block a user