Project lint checked and step added to config.yml

This commit is contained in:
2022-10-02 17:43:52 +01:00
parent e07e10079e
commit 8100f0b879
26 changed files with 71 additions and 63 deletions

View File

@@ -0,0 +1,30 @@
import 'dart:io';
// ignore: depend_on_referenced_packages
import 'package:dio/dio.dart';
import 'package:retrofit/retrofit.dart';
import '../../main.dart';
mixin SafeApiCall {
Future<T> getDataFromApiCall<T>(Future<HttpResponse<T>> apiCall) async {
try {
HttpResponse<T> httpResponse = await apiCall;
return httpResponse.data;
} on DioError catch(dioError) {
Map<String, dynamic>? errorResponse = dioError.response?.data?["error"];
String error;
if (errorResponse?["error"] != null){
error = errorResponse!["error"];
} else if (dioError.error != null){
error = dioError.error;
} else {
error = "Failed to retrieve data from api";
}
logger.e(dioError.error);
throw HttpException(error);
}
}
}