mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-16 05:33:17 +00:00
feat: Implement error handling for server installation
Now user gets notified when connection error occurs
This commit is contained in:
parent
1dfd2180d2
commit
65f5d987e2
|
@ -113,7 +113,7 @@ class CloudflareApi extends DnsProviderApi {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<void> removeSimilarRecords({
|
||||
Future<APIGenericResult<void>> removeSimilarRecords({
|
||||
required final ServerDomain domain,
|
||||
final String? ip4,
|
||||
}) async {
|
||||
|
@ -139,9 +139,16 @@ class CloudflareApi extends DnsProviderApi {
|
|||
await Future.wait(allDeleteFutures);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
return APIGenericResult(
|
||||
success: false,
|
||||
data: null,
|
||||
message: e.toString(),
|
||||
);
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
return APIGenericResult(success: true, data: null);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -183,7 +190,7 @@ class CloudflareApi extends DnsProviderApi {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<void> createMultipleDnsRecords({
|
||||
Future<APIGenericResult<void>> createMultipleDnsRecords({
|
||||
required final ServerDomain domain,
|
||||
final String? ip4,
|
||||
}) async {
|
||||
|
@ -206,9 +213,18 @@ class CloudflareApi extends DnsProviderApi {
|
|||
} on DioError catch (e) {
|
||||
print(e.message);
|
||||
rethrow;
|
||||
} catch (e) {
|
||||
print(e);
|
||||
return APIGenericResult(
|
||||
success: false,
|
||||
data: null,
|
||||
message: e.toString(),
|
||||
);
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
return APIGenericResult(success: true, data: null);
|
||||
}
|
||||
|
||||
List<DnsRecord> projectDnsRecords(
|
||||
|
|
|
@ -14,11 +14,11 @@ abstract class DnsProviderApi extends ApiMap {
|
|||
Future<List<DnsRecord>> getDnsRecords({
|
||||
required final ServerDomain domain,
|
||||
});
|
||||
Future<void> removeSimilarRecords({
|
||||
Future<APIGenericResult<void>> removeSimilarRecords({
|
||||
required final ServerDomain domain,
|
||||
final String? ip4,
|
||||
});
|
||||
Future<void> createMultipleDnsRecords({
|
||||
Future<APIGenericResult<void>> createMultipleDnsRecords({
|
||||
required final ServerDomain domain,
|
||||
final String? ip4,
|
||||
});
|
||||
|
|
|
@ -790,11 +790,13 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<void> createReverseDns({
|
||||
Future<APIGenericResult<void>> createReverseDns({
|
||||
required final ServerHostingDetails serverDetails,
|
||||
required final ServerDomain domain,
|
||||
}) async {
|
||||
/// TODO remove from provider interface
|
||||
const bool success = true;
|
||||
return APIGenericResult(success: success, data: null);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -788,7 +788,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<void> createReverseDns({
|
||||
Future<APIGenericResult<void>> createReverseDns({
|
||||
required final ServerHostingDetails serverDetails,
|
||||
required final ServerDomain domain,
|
||||
}) async {
|
||||
|
@ -803,8 +803,15 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
|||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
return APIGenericResult(
|
||||
success: false,
|
||||
data: null,
|
||||
message: e.toString(),
|
||||
);
|
||||
} finally {
|
||||
close(client);
|
||||
}
|
||||
|
||||
return APIGenericResult(success: true, data: null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@ abstract class ServerProviderApi extends ApiMap {
|
|||
required final String domainName,
|
||||
required final String serverType,
|
||||
});
|
||||
Future<void> createReverseDns({
|
||||
Future<APIGenericResult<void>> createReverseDns({
|
||||
required final ServerHostingDetails serverDetails,
|
||||
required final ServerDomain domain,
|
||||
});
|
||||
|
|
|
@ -334,21 +334,9 @@ class ServerInstallationRepository {
|
|||
final ServerProviderApi serverApi =
|
||||
ApiController.currentServerProviderApiFactory!.getServerProvider();
|
||||
|
||||
await dnsProviderApi.removeSimilarRecords(
|
||||
ip4: serverDetails.ip4,
|
||||
domain: domain,
|
||||
);
|
||||
|
||||
try {
|
||||
await dnsProviderApi.createMultipleDnsRecords(
|
||||
ip4: serverDetails.ip4,
|
||||
domain: domain,
|
||||
);
|
||||
} on DioError catch (e) {
|
||||
void showDomainErrorPopUp(final String error) {
|
||||
showPopUpAlert(
|
||||
alertTitle: e.response!.data['errors'][0]['code'] == 1038
|
||||
? 'modals.you_cant_use_this_api'.tr()
|
||||
: 'domain.error'.tr(),
|
||||
alertTitle: error,
|
||||
description: 'modals.delete_server_volume'.tr(),
|
||||
cancelButtonOnPressed: onCancel,
|
||||
actionButtonTitle: 'basis.delete'.tr(),
|
||||
|
@ -359,14 +347,50 @@ class ServerInstallationRepository {
|
|||
onCancel();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
final APIGenericResult removingResult =
|
||||
await dnsProviderApi.removeSimilarRecords(
|
||||
ip4: serverDetails.ip4,
|
||||
domain: domain,
|
||||
);
|
||||
|
||||
if (!removingResult.success) {
|
||||
showDomainErrorPopUp('domain.error'.tr());
|
||||
return false;
|
||||
}
|
||||
|
||||
await serverApi.createReverseDns(
|
||||
bool createdSuccessfully = false;
|
||||
String errorMessage = 'domain.error'.tr();
|
||||
try {
|
||||
final APIGenericResult createResult =
|
||||
await dnsProviderApi.createMultipleDnsRecords(
|
||||
ip4: serverDetails.ip4,
|
||||
domain: domain,
|
||||
);
|
||||
createdSuccessfully = createResult.success;
|
||||
} on DioError catch (e) {
|
||||
if (e.response!.data['errors'][0]['code'] == 1038) {
|
||||
errorMessage = 'modals.you_cant_use_this_api'.tr();
|
||||
}
|
||||
}
|
||||
|
||||
if (!createdSuccessfully) {
|
||||
showDomainErrorPopUp(errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
final APIGenericResult createReverseResult =
|
||||
await serverApi.createReverseDns(
|
||||
serverDetails: serverDetails,
|
||||
domain: domain,
|
||||
);
|
||||
|
||||
if (!createReverseResult.success) {
|
||||
showDomainErrorPopUp(errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue