api_error_parser_plus 0.3.0
api_error_parser_plus: ^0.3.0 copied to clipboard
A robust and type-safe library for parsing API responses and converting error codes into user-friendly messages with comprehensive error handling and validation.
Changelog #
0.3.0 - 2025-10-27 #
🎯 Meta Field Support #
- NEW: Added optional
metafield support in error messagesErrorMessageEntity.meta- nullableMap<String, dynamic>for dynamic error metadata- Backend can send or omit
metafield with arbitrary data structure - No default empty object -
nullwhen not provided by backend
- ADDED: Type-safe meta accessor methods:
metaInt(String key)- safely get integer valuesmetaDouble(String key)- safely get double valuesmetaStr(String key)- safely get string valuesmetaBool(String key)- safely get boolean valuesmetaMap(String key)- safely get nested map values
- ADDED: Template interpolation with
interpolate(String template)method- Replaces
{key}placeholders with values frommeta - Example:
"Min {min}, max {max}"→"Min 8, max 20"
- Replaces
- UPDATED:
toString()method includesmetafield - TESTED: 15 new test cases covering all meta scenarios
📚 Migration Guide from v0.2.0 #
- Fully backward compatible - no changes required for existing code
metafield isnullfor responses without metadata- Use new accessor methods for type-safe meta value extraction
- See
example/meta_usage_guide.mdfor detailed usage examples
✅ Use Cases #
- Validation errors with min/max constraints
- Product availability with ETA information
- Date format validation with expected/received formats
- Dynamic error parameters for localized messages
🔧 Technical Details #
metais parsed only if present and is a valid Map- Invalid meta types are treated as
null(graceful degradation) - No schema validation - application handles meta interpretation
- All existing tests (6) continue to pass
0.2.0 - 2025-01-15 #
🚀 Major API Format Update #
- NEW: Support for simplified API response format
- Success responses no longer require "data" wrapper (direct JSON response)
- Error responses still use "errors" field in root
- Enhanced
fromJsonSafemethod automatically detects response type
- IMPROVED: Type-safe parsing with
ParseResult<T>return types - ADDED: New test resources for different response formats
- UPDATED: Documentation with new API format examples
📚 Migration Guide from v0.1.0 #
New API Format (Recommended)
- Success responses: Return data directly
{"id": 1, "name": "Tom"} - Error responses: Keep current format
{"errors": [...]} - Library automatically detects response type based on "errors" field presence
Breaking Changes
fromJsonSafenow returnsParseResult<ApiResponseEntity<T>>instead of direct entity- Use
result.dataOrThroworresult.dataOrNullto access parsed data
⚡ Benefits #
- Cleaner API responses without unnecessary data wrappers
- Better type safety with ParseResult pattern
- Automatic response type detection
- Backward compatible with legacy format
0.1.0 - 2025-10-14 #
🗑️ Breaking Changes #
- REMOVED: Complete pagination logic and related classes
- Removed
ApiResponsePaginationandApiResponsePaginationEntity - Removed
PaginationandPaginationEntityclasses - Removed
ParserResponseWithPaginationEntity - Simplified
ApiParserSuccessResponse(removedpaginationfield)
- Removed
- Simplified: API response handling focuses only on data and errors
📚 Migration Guide from v0.0.4 #
- Remove any usage of pagination-related classes
ApiParserSuccessResponseno longer haspaginationfield- All pagination handling should be implemented in application layer
⚠️ Why Removed? #
Pagination logic was removed to keep the library focused on its core responsibility: error parsing and message handling. Pagination is better handled at the application level or in dedicated data layer components.
0.0.4 - 2025-10-14 #
🚀 Major Enhancements #
Added
- ErrorTarget enum: Strong type safety for error targets (
ErrorTarget.field,ErrorTarget.common) - ParseResult: Comprehensive result handling for safer parsing operations
- ApiParserConfig: Flexible configuration system with predefined environments
ApiParserConfig.production: Minimal logging, graceful error handlingApiParserConfig.debug: Detailed logging for developmentApiParserConfig.testing: Strict validation for tests
- Safe parsing methods:
fromJsonSafe()variants with detailed error reporting - Enhanced validation: Automatic validation of error structure and required fields
- Error analysis tools:
getUnknownErrorCodes(): Identify unmapped error codesisValidErrorMessage(): Validate error message structure
Enhanced
- Robust error handling: Better exception handling and error reporting
- Type safety: Eliminated magic strings and improved type checking
- Backward compatibility: All existing APIs continue to work
- Documentation: Comprehensive README with migration guide and examples
- Test coverage: Enhanced test suite with new configuration options
Fixed
- JSON parsing errors: Proper validation and error reporting for malformed data
- Null safety: Better handling of null and empty values
- Field validation: Strict validation for field target requirements
- Memory efficiency: Optimized error processing for large error lists
🔧 Breaking Changes #
ParserMessageEntity.targettype changed fromStringtoErrorTarget- Direct string comparisons with error targets should be replaced with enum usage
📚 Migration Guide #
- Replace string comparisons:
error.target == "field"→error.target == ErrorTarget.field - Add configuration parameter to
ApiParserconstructor (optional) - Consider migrating to
fromJsonSafemethods for better error handling
0.0.3 Previous Version #
- Added ability to parse lists at the root of JSON responses. Added fromJsonList method to ApiResponseEntity class.
0.0.2 Previous Version #
- Added hashCode and operator for ParseMessageEntity and ErrorSourceEntity to compare object when testing bloc(integration tests).
0.0.1 Initial Version #
- Initial version with basic API error parsing functionality