Skip to content

πŸ”§ Patch Release v2.0.3 - Error Handling & Response Validation

Choose a tag to compare

@PaulGossen PaulGossen released this 09 Nov 16:01
· 46 commits to main since this release

πŸ“‹ Overview

This patch release improves error handling for malformed JSON responses and corrects the UnregisterResponse class to match real API response structure with proper type conversion.


✨ Improvements

Enhanced JSON Error Messages

Improved error messages when the API returns invalid JSON responses:

Before:

ApiException: Invalid JSON response from API

After:

ApiException: Invalid JSON response from API: Syntax error. Body: {"api_version":"1.2",...}

Benefits:

  • Full response body included in error message (no truncation)
  • JSON error details immediately visible
  • HTTP status code in error context
  • Faster debugging of API issues

Modified: src/Client/ApiClient.php


πŸ› Bug Fixes

UnregisterResponse Type Correction

Fixed UnregisterResponse to match actual API response structure:

Before (Incorrect):

public string $modified;  // Was expecting string 'Y' or 'N'
public ?string $note;     // Using is_string() check

After (Correct):

public bool $modified;    // Properly converted from 'Y'/'N' to boolean
public ?string $note;     // Using TypeConverter::toString()

Changes:

  • modified property now correctly typed as bool
  • Uses TypeConverter::toBool() to convert 'Y'/'N' β†’ true/false
  • Uses TypeConverter::toString() for note field
  • Added test with real production API response

Modified: src/Response/ApiKey/UnregisterResponse.php


πŸ“ Migration Guide

For JSON Error Handling

No code changes required. Error messages are now more informative automatically.

For UnregisterResponse Users

If you were checking the modified property:

// Before (string comparison)
if ($response->modified === 'Y') {
    // API key was deleted
}

// After (boolean check)
if ($response->modified) {
    // API key was deleted
}

πŸ§ͺ Quality Assurance

  • βœ… 1146/1146 Unit Tests Passing (2296 assertions)
  • βœ… PHPStan Level 9: 0 errors (654 files analyzed)
  • βœ… PHP CS Fixer: 0 violations
  • βœ… New Test: Real production API response validation

πŸ“¦ Files Changed

3 files changed: 23 insertions(+), 22 deletions(-)

Modified Files

  • src/Client/ApiClient.php - Enhanced JSON error messages
  • src/Response/ApiKey/UnregisterResponse.php - Correct type conversion
  • tests/Unit/Response/ApiKey/UnregisterResponseTest.php - Boolean assertions

🎯 Impact

Low Impact

  • JSON error improvements: Automatic, no code changes needed
  • UnregisterResponse: Only affects users checking modified property with string comparison

Recommended Actions

  1. Update any string comparisons on modified property to boolean checks
  2. Benefit from improved error messages automatically

Full Changelog: v2.0.2...v2.0.3