1
+ use axum:: http:: HeaderValue ;
1
2
use chrono:: DateTime ;
2
3
use chrono_tz:: Tz ;
3
4
use reqwest:: { Client , ClientBuilder , StatusCode } ;
@@ -32,20 +33,18 @@ pub struct UnifiAPI<'a> {
32
33
}
33
34
34
35
impl < ' a > UnifiAPI < ' a > {
35
- pub async fn new ( ) -> Result < Self , ( ) > {
36
+ pub async fn try_new ( ) -> Result < Self , String > {
36
37
let environment: & Environment = ENVIRONMENT . get ( ) . expect ( "Environment not set" ) ;
37
38
38
39
let mut headers = reqwest:: header:: HeaderMap :: with_capacity ( 2 ) ;
39
40
headers. insert (
40
41
reqwest:: header:: CONTENT_TYPE ,
41
- reqwest :: header :: HeaderValue :: from_static ( "application/json" ) ,
42
+ HeaderValue :: from_static ( "application/json" ) ,
42
43
) ;
43
44
headers. insert (
44
45
"X-API-Key" ,
45
- environment
46
- . unifi_api_key
47
- . parse ( )
48
- . expect ( "Could not parse API Key" ) ,
46
+ HeaderValue :: from_str ( & environment. unifi_api_key )
47
+ . map_err ( |e| format ! ( "Failed to set X-API-Key header: {e}" ) ) ?,
49
48
) ;
50
49
51
50
let client = ClientBuilder :: new ( )
@@ -70,8 +69,7 @@ impl<'a> UnifiAPI<'a> {
70
69
let id = match unifi_api. get_default_site_id ( ) . await {
71
70
Ok ( id) => id,
72
71
Err ( e) => {
73
- error ! ( "Failed to fetch default site ID: {}" , e) ;
74
- return Err ( ( ) ) ;
72
+ return Err ( format ! ( "Failed to fetch default site ID: {e}" ) ) ;
75
73
}
76
74
} ;
77
75
info ! ( "Default site ID found: {}" , id) ;
0 commit comments