From: Shan Shaji <s.shaji@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH proxmox_dart_api_client v2 2/2] fix: add explicit throw of `HandShakeException`
Date: Thu, 4 Sep 2025 12:09:56 +0200 [thread overview]
Message-ID: <20250904100956.79194-4-s.shaji@proxmox.com> (raw)
In-Reply-To: <20250904100956.79194-1-s.shaji@proxmox.com>
The `cronet_http` is throwing `ClientException` [0] instead of
`HandShakeException` when the certificate is not valid.
Due to this the exception was directly shown in the UI. Inorder to make
the error more user friendly catch the `ClientException` and rethrow
`HandShakeException` if the certificate is not valid.
[0] - https://github.com/dart-lang/http/blob/ef05b3744424885d93f88a6a50664fb5b7d5cbdb/pkgs/cronet_http/lib/src/cronet_client.dart#L327
Signed-off-by: Shan Shaji <s.shaji@proxmox.com>
---
lib/src/authenticate.dart | 31 ++++++++++++++++++++++---------
1 file changed, 22 insertions(+), 9 deletions(-)
diff --git a/lib/src/authenticate.dart b/lib/src/authenticate.dart
index 118408f..a142a4c 100644
--- a/lib/src/authenticate.dart
+++ b/lib/src/authenticate.dart
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:convert';
+import 'dart:io';
import 'package:http/http.dart' as http;
import 'package:proxmox_dart_api_client/proxmox_dart_api_client.dart';
@@ -56,6 +57,11 @@ Future<ProxmoxApiClient> authenticate(
} on TimeoutException catch (_) {
throw ProxmoxApiException(
'Authentication takes unusually long, check network connection', 408);
+ } on http.ClientException catch (e) {
+ if (e.message.contains('net::ERR_CERT_AUTHORITY_INVALID')) {
+ throw HandshakeException(e.message);
+ }
+ rethrow;
}
}
@@ -64,14 +70,21 @@ Future<List<PveAccessDomainModel?>> accessDomains(
bool validateSSL, {
http.Client? httpClient,
}) async {
- httpClient ??= getCustomIOHttpClient(validateSSL: validateSSL);
+ try {
+ httpClient ??= getCustomIOHttpClient(validateSSL: validateSSL);
- final path = '/api2/json/access/domains';
- final response = await httpClient
- .get(apiBaseUrl.replace(path: path))
- .timeout(Duration(seconds: 25));
- var data = (json.decode(response.body)['data'] as List).map((f) {
- return serializers.deserializeWith(PveAccessDomainModel.serializer, f);
- });
- return data.toList();
+ final path = '/api2/json/access/domains';
+ final response = await httpClient
+ .get(apiBaseUrl.replace(path: path))
+ .timeout(Duration(seconds: 25));
+ var data = (json.decode(response.body)['data'] as List).map((f) {
+ return serializers.deserializeWith(PveAccessDomainModel.serializer, f);
+ });
+ return data.toList();
+ } on http.ClientException catch (e) {
+ if (e.message.contains('net::ERR_CERT_AUTHORITY_INVALID')) {
+ throw HandshakeException(e.message);
+ }
+ rethrow;
+ }
}
--
2.47.2
_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
next prev parent reply other threads:[~2025-09-04 10:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-04 10:09 [pve-devel] [PATCH proxmox_dart_api_client/pve_flutter_frontend v2 0/3] fix: android: add support to honor user installed certificate Shan Shaji
2025-09-04 10:09 ` [pve-devel] [PATCH pve_flutter_frontend v2 1/1] fix: android: add network config to support custom certificates Shan Shaji
2025-09-04 10:09 ` [pve-devel] [PATCH proxmox_dart_api_client v2 1/2] fix: android: use `cronet_http` package to honor " Shan Shaji
2025-09-04 10:09 ` Shan Shaji [this message]
2025-09-05 8:43 ` [pve-devel] [PATCH proxmox_dart_api_client/pve_flutter_frontend v2 0/3] fix: android: add support to honor user installed certificate Michael Köppl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250904100956.79194-4-s.shaji@proxmox.com \
--to=s.shaji@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.