Converts the exception to a JSON-compatible map.
Map<String, dynamic> toJson() => <String, dynamic>{ 'message': message, if (details != null) 'errors': details, };