@@ -73,7 +73,7 @@ public async
73
73
await gatewayResponse . Content . ReadBaseResponseAsJsonAsync < LcgResponse > ( cancellationToken ,
74
74
JsonSerializerOptions ) ) ;
75
75
}
76
-
76
+
77
77
if ( gatewayResponse . StatusCode == HttpStatusCode . Unauthorized ) return new UnauthenticatedError ( ) ;
78
78
79
79
if ( ! gatewayResponse . IsProblem ( ) )
@@ -82,8 +82,8 @@ await gatewayResponse.Content.ReadBaseResponseAsJsonAsync<LcgResponse>(cancellat
82
82
var problem =
83
83
await gatewayResponse . Content . ReadAsJsonAsync < ProblemDetails > ( cancellationToken ,
84
84
JsonSerializerOptions ) ;
85
-
86
- return problem . Type switch
85
+
86
+ return problem . Type switch
87
87
{
88
88
"Device.NotFound" => new NotFound ( ) ,
89
89
"Device.NotOnline" => new DeviceOffline ( ) ,
@@ -96,7 +96,26 @@ await gatewayResponse.Content.ReadAsJsonAsync<ProblemDetails>(cancellationToken,
96
96
public async Task < RootResponse > GetRoot ( CancellationToken cancellationToken = default )
97
97
{
98
98
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 ) ) ;
100
119
}
101
120
102
121
private string GetUserAgent ( )
0 commit comments