feat: Implement distinction for connection errors on server type page

Now user gets notified when connection error occurs
pull/149/head
NaiJi ✨ 2022-11-28 23:11:08 +04:00
parent bd33b8d679
commit 1df5f6594d
4 changed files with 53 additions and 12 deletions

View File

@ -709,7 +709,8 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
}
@override
Future<List<ServerProviderLocation>> getAvailableLocations() async {
Future<APIGenericResult<List<ServerProviderLocation>>>
getAvailableLocations() async {
List<ServerProviderLocation> locations = [];
final Dio client = await getClient();
@ -730,15 +731,20 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
.toList();
} catch (e) {
print(e);
return APIGenericResult(
data: [],
success: false,
message: e.toString(),
);
} finally {
close(client);
}
return locations;
return APIGenericResult(data: locations, success: true);
}
@override
Future<List<ServerType>> getServerTypesByLocation({
Future<APIGenericResult<List<ServerType>>> getServerTypesByLocation({
required final ServerProviderLocation location,
}) async {
final List<ServerType> types = [];
@ -771,11 +777,16 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
}
} catch (e) {
print(e);
return APIGenericResult(
data: [],
success: false,
message: e.toString(),
);
} finally {
close(client);
}
return types;
return APIGenericResult(data: types, success: true);
}
@override

View File

@ -707,7 +707,8 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
}
@override
Future<List<ServerProviderLocation>> getAvailableLocations() async {
Future<APIGenericResult<List<ServerProviderLocation>>>
getAvailableLocations() async {
List<ServerProviderLocation> locations = [];
final Dio client = await getClient();
@ -728,15 +729,20 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
.toList();
} catch (e) {
print(e);
return APIGenericResult(
success: false,
data: [],
message: e.toString(),
);
} finally {
close(client);
}
return locations;
return APIGenericResult(success: true, data: locations);
}
@override
Future<List<ServerType>> getServerTypesByLocation({
Future<APIGenericResult<List<ServerType>>> getServerTypesByLocation({
required final ServerProviderLocation location,
}) async {
final List<ServerType> types = [];
@ -769,11 +775,16 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
}
} catch (e) {
print(e);
return APIGenericResult(
data: [],
success: false,
message: e.toString(),
);
} finally {
close(client);
}
return types;
return APIGenericResult(data: types, success: true);
}
@override

View File

@ -22,8 +22,9 @@ class ProviderApiTokenValidation {
abstract class ServerProviderApi extends ApiMap {
Future<List<ServerBasicInfo>> getServers();
Future<List<ServerProviderLocation>> getAvailableLocations();
Future<List<ServerType>> getServerTypesByLocation({
Future<APIGenericResult<List<ServerProviderLocation>>>
getAvailableLocations();
Future<APIGenericResult<List<ServerType>>> getServerTypesByLocation({
required final ServerProviderLocation location,
});

View File

@ -123,9 +123,18 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
return [];
}
return ApiController.currentServerProviderApiFactory!
final APIGenericResult apiResult = await ApiController
.currentServerProviderApiFactory!
.getServerProvider()
.getAvailableLocations();
if (!apiResult.success) {
getIt<NavigationService>().showSnackBar(
'initializing.could_not_connect'.tr(),
);
}
return apiResult.data;
}
Future<List<ServerType>> fetchAvailableTypesByLocation(
@ -135,9 +144,18 @@ class ServerInstallationCubit extends Cubit<ServerInstallationState> {
return [];
}
return ApiController.currentServerProviderApiFactory!
final APIGenericResult apiResult = await ApiController
.currentServerProviderApiFactory!
.getServerProvider()
.getServerTypesByLocation(location: location);
if (!apiResult.success) {
getIt<NavigationService>().showSnackBar(
'initializing.could_not_connect'.tr(),
);
}
return apiResult.data;
}
void setServerProviderKey(final String serverProviderKey) async {