@@ -73,7 +73,7 @@ public async
7373 await gatewayResponse . Content . ReadBaseResponseAsJsonAsync < LcgResponse > ( cancellationToken ,
7474 JsonSerializerOptions ) ) ;
7575 }
76-
76+
7777 if ( gatewayResponse . StatusCode == HttpStatusCode . Unauthorized ) return new UnauthenticatedError ( ) ;
7878
7979 if ( ! gatewayResponse . IsProblem ( ) )
@@ -82,8 +82,8 @@ await gatewayResponse.Content.ReadBaseResponseAsJsonAsync<LcgResponse>(cancellat
8282 var problem =
8383 await gatewayResponse . Content . ReadAsJsonAsync < ProblemDetails > ( cancellationToken ,
8484 JsonSerializerOptions ) ;
85-
86- return problem . Type switch
85+
86+ return problem . Type switch
8787 {
8888 "Device.NotFound" => new NotFound ( ) ,
8989 "Device.NotOnline" => new DeviceOffline ( ) ,
@@ -96,7 +96,26 @@ await gatewayResponse.Content.ReadAsJsonAsync<ProblemDetails>(cancellationToken,
9696 public async Task < RootResponse > GetRoot ( CancellationToken cancellationToken = default )
9797 {
9898 using var rootResponse = await _httpClient . GetAsync ( OpenShockEndpoints . V1 . Root , cancellationToken ) ;
99- return await rootResponse . Content . ReadBaseResponseAsJsonAsync < RootResponse > ( cancellationToken , JsonSerializerOptions ) ;
99+ return await rootResponse . Content . ReadBaseResponseAsJsonAsync < RootResponse > ( cancellationToken ,
100+ JsonSerializerOptions ) ;
101+ }
102+
103+ /// <inheritdoc />
104+ public async Task < OneOf < Success < SelfResponse > , UnauthenticatedError > > GetSelf (
105+ CancellationToken cancellationToken = default )
106+ {
107+ using var selfResponse = await _httpClient . GetAsync ( OpenShockEndpoints . V1 . Users . Self , cancellationToken ) ;
108+
109+ if ( ! selfResponse . IsSuccess ( ) )
110+ {
111+ if ( selfResponse . StatusCode == HttpStatusCode . Unauthorized ) return new UnauthenticatedError ( ) ;
112+
113+ throw new OpenShockApiError ( "Failed to get user self" , selfResponse . StatusCode ) ;
114+ }
115+
116+ return new Success < SelfResponse > (
117+ await selfResponse . Content . ReadBaseResponseAsJsonAsync < SelfResponse > ( cancellationToken ,
118+ JsonSerializerOptions ) ) ;
100119 }
101120
102121 private string GetUserAgent ( )
0 commit comments