Skip to content

fix: handle null response after claude reset#13

Closed
rasyid7 wants to merge 2 commits into
eddmann:mainfrom
rasyid7:fix-after-reset
Closed

fix: handle null response after claude reset#13
rasyid7 wants to merge 2 commits into
eddmann:mainfrom
rasyid7:fix-after-reset

Conversation

@rasyid7
Copy link
Copy Markdown
Contributor

@rasyid7 rasyid7 commented Apr 3, 2026

Fix: Server returned invalid response #10

Summary of Changes

Modified ClaudeMeter to handle a specific API response case when the Claude session has been reset.

Problem

When Claude's session resets, the API returns resets_at: null for five_hour:

{
    "five_hour": {
        "utilization": 0.0,
        "resets_at": null
    },
    ...
}

Previously, this caused an error: MappingError.missingCriticalField(field: "fiveHour.resetsAt")
Solution

  1. UsageLimit.swift - Made resetAt optional
    • Changed resetAt: Date → resetAt: Date?
    • resetDescription now returns "Starts when a message is sent" when nil
    • Updated isResetting and isAtRisk to handle nil safely
  2. UsageAPIResponse.swift - Handle null reset dates
    • Session usage with resets_at: null → utilization forced to 0%
    • Same handling for optional sevenDaySonnet
  3. UsageCardView.swift - Updated UI text
    • When resetAt is nil: shows "Starts when a message is sent"
    • When resetAt exists: shows "Resets in X hours"
  4. NotificationServiceProtocol.swift & NotificationService.swift - Updated for optional dates
    • Changed resetTime: Date → resetTime: Date?
    • Notification body handles nil reset time gracefully
  5. Test spy updated to match new protocol signature
image

@eddmann
Copy link
Copy Markdown
Owner

eddmann commented May 18, 2026

Thanks Rasyid. The null resets_at issue raised here has been addressed via #21, and your contribution has been acknowledged in that PR.

The final implementation follows the stricter version that still fails malformed non-null reset dates, while accepting truly null reset timestamps.

@eddmann eddmann closed this May 18, 2026
@eddmann
Copy link
Copy Markdown
Owner

eddmann commented May 18, 2026

Thanks again Rasyid. The null resets_at fix is now included in ClaudeMeter v1.3.1.

The released implementation accepts truly null reset timestamps after a usage window resets, while still treating malformed non-null reset dates as invalid responses. Your PR helped identify and validate the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants