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
|
@override
|
||||||
Future<void> removeSimilarRecords({
|
Future<APIGenericResult<void>> removeSimilarRecords({
|
||||||
required final ServerDomain domain,
|
required final ServerDomain domain,
|
||||||
final String? ip4,
|
final String? ip4,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -139,9 +139,16 @@ class CloudflareApi extends DnsProviderApi {
|
||||||
await Future.wait(allDeleteFutures);
|
await Future.wait(allDeleteFutures);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
|
return APIGenericResult(
|
||||||
|
success: false,
|
||||||
|
data: null,
|
||||||
|
message: e.toString(),
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
close(client);
|
close(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return APIGenericResult(success: true, data: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -183,7 +190,7 @@ class CloudflareApi extends DnsProviderApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> createMultipleDnsRecords({
|
Future<APIGenericResult<void>> createMultipleDnsRecords({
|
||||||
required final ServerDomain domain,
|
required final ServerDomain domain,
|
||||||
final String? ip4,
|
final String? ip4,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -206,9 +213,18 @@ class CloudflareApi extends DnsProviderApi {
|
||||||
} on DioError catch (e) {
|
} on DioError catch (e) {
|
||||||
print(e.message);
|
print(e.message);
|
||||||
rethrow;
|
rethrow;
|
||||||
|
} catch (e) {
|
||||||
|
print(e);
|
||||||
|
return APIGenericResult(
|
||||||
|
success: false,
|
||||||
|
data: null,
|
||||||
|
message: e.toString(),
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
close(client);
|
close(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return APIGenericResult(success: true, data: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<DnsRecord> projectDnsRecords(
|
List<DnsRecord> projectDnsRecords(
|
||||||
|
|
|
@ -14,11 +14,11 @@ abstract class DnsProviderApi extends ApiMap {
|
||||||
Future<List<DnsRecord>> getDnsRecords({
|
Future<List<DnsRecord>> getDnsRecords({
|
||||||
required final ServerDomain domain,
|
required final ServerDomain domain,
|
||||||
});
|
});
|
||||||
Future<void> removeSimilarRecords({
|
Future<APIGenericResult<void>> removeSimilarRecords({
|
||||||
required final ServerDomain domain,
|
required final ServerDomain domain,
|
||||||
final String? ip4,
|
final String? ip4,
|
||||||
});
|
});
|
||||||
Future<void> createMultipleDnsRecords({
|
Future<APIGenericResult<void>> createMultipleDnsRecords({
|
||||||
required final ServerDomain domain,
|
required final ServerDomain domain,
|
||||||
final String? ip4,
|
final String? ip4,
|
||||||
});
|
});
|
||||||
|
|
|
@ -790,11 +790,13 @@ class DigitalOceanApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> createReverseDns({
|
Future<APIGenericResult<void>> createReverseDns({
|
||||||
required final ServerHostingDetails serverDetails,
|
required final ServerHostingDetails serverDetails,
|
||||||
required final ServerDomain domain,
|
required final ServerDomain domain,
|
||||||
}) async {
|
}) async {
|
||||||
/// TODO remove from provider interface
|
/// TODO remove from provider interface
|
||||||
|
const bool success = true;
|
||||||
|
return APIGenericResult(success: success, data: null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -788,7 +788,7 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> createReverseDns({
|
Future<APIGenericResult<void>> createReverseDns({
|
||||||
required final ServerHostingDetails serverDetails,
|
required final ServerHostingDetails serverDetails,
|
||||||
required final ServerDomain domain,
|
required final ServerDomain domain,
|
||||||
}) async {
|
}) async {
|
||||||
|
@ -803,8 +803,15 @@ class HetznerApi extends ServerProviderApi with VolumeProviderApi {
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print(e);
|
print(e);
|
||||||
|
return APIGenericResult(
|
||||||
|
success: false,
|
||||||
|
data: null,
|
||||||
|
message: e.toString(),
|
||||||
|
);
|
||||||
} finally {
|
} finally {
|
||||||
close(client);
|
close(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return APIGenericResult(success: true, data: null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ abstract class ServerProviderApi extends ApiMap {
|
||||||
required final String domainName,
|
required final String domainName,
|
||||||
required final String serverType,
|
required final String serverType,
|
||||||
});
|
});
|
||||||
Future<void> createReverseDns({
|
Future<APIGenericResult<void>> createReverseDns({
|
||||||
required final ServerHostingDetails serverDetails,
|
required final ServerHostingDetails serverDetails,
|
||||||
required final ServerDomain domain,
|
required final ServerDomain domain,
|
||||||
});
|
});
|
||||||
|
|
|
@ -334,21 +334,9 @@ class ServerInstallationRepository {
|
||||||
final ServerProviderApi serverApi =
|
final ServerProviderApi serverApi =
|
||||||
ApiController.currentServerProviderApiFactory!.getServerProvider();
|
ApiController.currentServerProviderApiFactory!.getServerProvider();
|
||||||
|
|
||||||
await dnsProviderApi.removeSimilarRecords(
|
void showDomainErrorPopUp(final String error) {
|
||||||
ip4: serverDetails.ip4,
|
|
||||||
domain: domain,
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await dnsProviderApi.createMultipleDnsRecords(
|
|
||||||
ip4: serverDetails.ip4,
|
|
||||||
domain: domain,
|
|
||||||
);
|
|
||||||
} on DioError catch (e) {
|
|
||||||
showPopUpAlert(
|
showPopUpAlert(
|
||||||
alertTitle: e.response!.data['errors'][0]['code'] == 1038
|
alertTitle: error,
|
||||||
? 'modals.you_cant_use_this_api'.tr()
|
|
||||||
: 'domain.error'.tr(),
|
|
||||||
description: 'modals.delete_server_volume'.tr(),
|
description: 'modals.delete_server_volume'.tr(),
|
||||||
cancelButtonOnPressed: onCancel,
|
cancelButtonOnPressed: onCancel,
|
||||||
actionButtonTitle: 'basis.delete'.tr(),
|
actionButtonTitle: 'basis.delete'.tr(),
|
||||||
|
@ -359,14 +347,50 @@ class ServerInstallationRepository {
|
||||||
onCancel();
|
onCancel();
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final APIGenericResult removingResult =
|
||||||
|
await dnsProviderApi.removeSimilarRecords(
|
||||||
|
ip4: serverDetails.ip4,
|
||||||
|
domain: domain,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!removingResult.success) {
|
||||||
|
showDomainErrorPopUp('domain.error'.tr());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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(
|
await serverApi.createReverseDns(
|
||||||
serverDetails: serverDetails,
|
serverDetails: serverDetails,
|
||||||
domain: domain,
|
domain: domain,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!createReverseResult.success) {
|
||||||
|
showDomainErrorPopUp(errorMessage);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue