add dart client to packages

This commit is contained in:
Neevash Ramdial
2021-01-07 12:09:26 -04:00
parent e7eb0a27f6
commit f28cc91301
160 changed files with 26368 additions and 0 deletions
@@ -0,0 +1,54 @@
import 'dart:convert';
/// Exception related to api calls
class ApiError extends Error {
/// Raw body of the response
final String body;
/// Json parsed body
final Map<String, dynamic> jsonData;
/// Http status code of the response
final int status;
/// Stream specific error code
int get code => _code;
int _code;
static Map<String, dynamic> _decode(String body) {
try {
if (body == null) {
return null;
}
return json.decode(body);
} on FormatException {
return null;
}
}
/// Creates a new ApiError instance using the response body and status code
ApiError(this.body, this.status) : jsonData = _decode(body) {
if (jsonData != null && jsonData.containsKey('code')) {
_code = jsonData['code'];
}
}
@override
bool operator ==(Object other) =>
identical(this, other) ||
other is ApiError &&
runtimeType == other.runtimeType &&
body == other.body &&
jsonData == other.jsonData &&
status == other.status &&
_code == other._code;
@override
int get hashCode =>
body.hashCode ^ jsonData.hashCode ^ status.hashCode ^ _code.hashCode;
@override
String toString() {
return 'ApiError{body: $body, jsonData: $jsonData, status: $status, code: $_code}';
}
}