@@ -28,7 +28,7 @@ impl gleam_core::io::HttpClient for HttpClient {
28
28
. try_into ( )
29
29
. expect ( "Unable to convert HTTP request for use by reqwest library" ) ;
30
30
let mut response = REQWEST_CLIENT
31
- . get_or_init ( init_client)
31
+ . get_or_init ( || init_client ( ) . expect ( "Unable to create reqwest client" ) )
32
32
. execute ( request)
33
33
. await
34
34
. map_err ( Error :: http) ?;
@@ -44,24 +44,21 @@ impl gleam_core::io::HttpClient for HttpClient {
44
44
}
45
45
}
46
46
47
- fn init_client ( ) -> Client {
48
- match get_certificate ( ) {
49
- Ok ( cert) => Client :: builder ( )
50
- . add_root_certificate ( cert)
51
- . build ( )
52
- . expect ( "Unable to build reqwest client with certificate" ) ,
53
- _ => Client :: new ( ) ,
54
- }
55
- }
56
-
57
- fn get_certificate ( ) -> Result < Certificate , Error > {
58
- let certificate_path = std:: env:: var ( "GLEAM_CACERTS_PATH" ) ?;
59
- let certificate_bytes = std:: fs:: read ( & certificate_path) ?;
60
-
61
- match Certificate :: from_pem ( & certificate_bytes) {
62
- Ok ( certificate) => Ok ( certificate) ,
63
- Err ( e) => Error :: CannotReadCertificate {
47
+ fn init_client ( ) -> Result < Client , Error > {
48
+ let certificate_path = std:: env:: var ( "GLEAM_CACERTS_PATH" )
49
+ . map_err ( |_| Error :: CannotReadCertificate { path : "" . into ( ) } ) ?;
50
+ let certificate_bytes =
51
+ std:: fs:: read ( & certificate_path) . map_err ( |_| Error :: CannotReadCertificate {
52
+ path : certificate_path. clone ( ) ,
53
+ } ) ?;
54
+ let certificate =
55
+ Certificate :: from_pem ( & certificate_bytes) . map_err ( |_| Error :: CannotReadCertificate {
56
+ path : certificate_path. clone ( ) ,
57
+ } ) ?;
58
+ Client :: builder ( )
59
+ . add_root_certificate ( certificate)
60
+ . build ( )
61
+ . map_err ( |_| Error :: CannotReadCertificate {
64
62
path : certificate_path,
65
- } ,
66
- }
63
+ } )
67
64
}
0 commit comments