getCountriesByCode method
Implementation
@override
Future<Countries> getCountriesByCode(String code) async {
try {
return await dio
.get('${ApiEndpoints.COUNTRIES}/$code',
options: Options(
validateStatus: (status) => status == 200 || status == 404))
.then((value) {
try {
return Countries.fromJson(value.data);
} catch (e) {
logger.error(TAG, e.toString(), {'method': 'getCountriesByCode'});
}
return Countries(list: []);
});
} on Exception catch (e) {
throw HttpHelper.decodeErrorResponse(e,
tag: TAG,
logger: logger,
defaultErrorMessage: 'Failed to get countries',
meta: {'code': code, 'method': 'getCountriesByCode'});
}
}