import 'package:json_annotation/json_annotation.dart'; part 'server.g.dart'; @JsonSerializable() class ErrorResponse implements Exception { final int code; final String details; final String source; final String error; const ErrorResponse({ required this.code, required this.details, required this.error, required this.source, }); @override String toString() { final buffer = StringBuffer('Error response (code: $code'); if (details.isNotEmpty) { buffer.write(', details: $details'); } if (error.isNotEmpty) { buffer.write(', error: $error'); } if (source.isNotEmpty) { buffer.write(', source: $source'); } buffer.write(')'); return buffer.toString(); } factory ErrorResponse.fromJson(Map json) => _$ErrorResponseFromJson(json); Map toJson() => _$ErrorResponseToJson(this); }