Skip to content

Commit

Permalink
fix(errors): proper error handling for api call
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanaidilp committed Feb 24, 2025
1 parent f5c1fce commit 856a7d8
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class DomainRemoteDataSourceImpl implements DomainRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<DomainModel>?>.fromJson(result, (
json,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class InfographicRemoteDataSourceImpl implements InfographicRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<InfographicModel>?>.fromJson(
result,
(json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class NewsRemoteDataSourceImpl implements NewsRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<NewsModel?>.fromJson(result, (json) {
if (json == null) {
return null;
Expand Down Expand Up @@ -81,6 +85,10 @@ class NewsRemoteDataSourceImpl implements NewsRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<NewsModel>?>.fromJson(result, (
json,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class NewsCategoryRemoteDataSourceImpl implements NewsCategoryRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<NewsCategoryModel>?>.fromJson(
result,
(json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class PressReleaseRemoteDataSourceImpl implements PressReleaseRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<PressReleaseModel?>.fromJson(result, (
json,
) {
Expand Down Expand Up @@ -80,6 +84,10 @@ class PressReleaseRemoteDataSourceImpl implements PressReleaseRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<PressReleaseModel>?>.fromJson(
result,
(json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ class PublicationRemoteDataSourceImpl implements PublicationRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<PublicationModel?>.fromJson(result, (
json,
) {
Expand Down Expand Up @@ -102,6 +106,10 @@ class PublicationRemoteDataSourceImpl implements PublicationRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<PublicationModel>?>.fromJson(
result,
(json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class StaticTableRemoteDataSourceImpl implements StaticTableRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<StaticTableModel?>.fromJson(result, (
json,
) {
Expand Down Expand Up @@ -80,6 +84,10 @@ class StaticTableRemoteDataSourceImpl implements StaticTableRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<StaticTableModel>?>.fromJson(
result,
(json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class StatisticClassificationRemoteDataSourceImpl
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response =
ApiResponseModel<List<StatisticClassificationModel>>.fromJson(result, (
json,
Expand Down Expand Up @@ -92,6 +96,10 @@ class StatisticClassificationRemoteDataSourceImpl
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response =
ApiResponseModel<List<StatisticClassificationModel>>.fromJson(result, (
json,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class StrategicIndicatorRemoteDataSourceImpl
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<StrategicIndicatorModel>?>.fromJson(
result,
(json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class SubjectCategoryRemoteDataSourceImpl
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<SubjectCategoryModel>?>.fromJson(
result,
(json) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class SubjectRemoteDataSourceImpl implements SubjectRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<SubjectModel>?>.fromJson(result, (
json,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class UnitDataRemoteDataSourceImpl implements UnitDataRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<UnitDataModel>?>.fromJson(result, (
json,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const _unitKey = 'unit';
class UnitDataModel extends UnitData {
const UnitDataModel({required super.id, required super.title});

factory UnitDataModel.fromJson(JSON json) =>
UnitDataModel(id: json[_idKey] as int, title: json[_unitKey] as String);
factory UnitDataModel.fromJson(JSON json) => UnitDataModel(
id: json[_idKey] as int,
title: json[_unitKey] as String? ?? '-',
);

JSON toJson() => {_idKey: id, _unitKey: title};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class VariableRemoteDataSourceImpl implements VariableRemoteDataSource {
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<VariableModel>?>.fromJson(result, (
json,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ class VerticalVariableRemoteDataSourceImpl
},
);

if (result.containsKey('status') && result['status'] == 'Error') {
throw ApiException(result['message']?.toString() ?? '');
}

final response = ApiResponseModel<List<VerticalVariableModel>?>.fromJson(
result,
(json) {
Expand Down

0 comments on commit 856a7d8

Please sign in to comment.