Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit404de0d

Browse files
committed
fix: handle missing usertheme_preference on sign in
1 parentae51d0e commit404de0d

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

‎Coder Desktop/CoderSDK/Client.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public struct Client {
4444
throw.network(error)
4545
}
4646
guardlet httpResponse= respas?HTTPURLResponseelse{
47-
throw.unexpectedResponse(data)
47+
throw.unexpectedResponse(String(data: data, encoding:.utf8)??"<non-utf8 data>")
4848
}
4949
returnHTTPResponse(resp: httpResponse, data: data, req: req)
5050
}
@@ -72,7 +72,7 @@ public struct Client {
7272

7373
func responseAsError(_ resp:HTTPResponse)->ClientError{
7474
do{
75-
letbody=tryClient.decoder.decode(Response.self, from: resp.data)
75+
letbody=trydecode(Response.self, from: resp.data)
7676
letout=APIError(
7777
response: body,
7878
statusCode: resp.resp.statusCode,
@@ -81,7 +81,24 @@ public struct Client {
8181
)
8282
return.api(out)
8383
}catch{
84-
return.unexpectedResponse(resp.data.prefix(1024))
84+
return.unexpectedResponse(String(data: resp.data, encoding:.utf8)??"<non-utf8 data>")
85+
}
86+
}
87+
88+
// Wrapper around JSONDecoder.decode that displays useful error messages from `DecodingError`.
89+
func decode<T>(_:T.Type, from data:Data)throws(ClientError)->Twhere T:Decodable{
90+
do{
91+
returntryClient.decoder.decode(T.self, from: data)
92+
}catchletDecodingError.keyNotFound(_, context){
93+
throw.unexpectedResponse("Key not found:\(context.debugDescription)")
94+
}catchletDecodingError.valueNotFound(_, context){
95+
throw.unexpectedResponse("Value not found:\(context.debugDescription)")
96+
}catchletDecodingError.typeMismatch(_, context){
97+
throw.unexpectedResponse("Type mismatch:\(context.debugDescription)")
98+
}catchletDecodingError.dataCorrupted(context){
99+
throw.unexpectedResponse("Data corrupted:\(context.debugDescription)")
100+
}catch{
101+
throw.unexpectedResponse(String(data: data.prefix(1024), encoding:.utf8)??"<non-utf8 data>")
85102
}
86103
}
87104
}
@@ -119,7 +136,7 @@ public struct FieldValidation: Decodable, Sendable {
119136
publicenumClientError:Error{
120137
case api(APIError)
121138
case network(anyError)
122-
case unexpectedResponse(Data)
139+
case unexpectedResponse(String)
123140
case encodeFailure(anyError)
124141

125142
publicvardescription:String{
@@ -129,7 +146,7 @@ public enum ClientError: Error {
129146
caselet.network(error):
130147
error.localizedDescription
131148
caselet.unexpectedResponse(data):
132-
"Unexpectedor non HTTPresponse:\(data)"
149+
"Unexpected response:\(data)"
133150
caselet.encodeFailure(error):
134151
"Failed to encode body:\(error.localizedDescription)"
135152
}

‎Coder Desktop/CoderSDK/Deployment.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ public extension Client {
66
guard res.resp.statusCode==200else{
77
throwresponseAsError(res)
88
}
9-
do{
10-
returntryClient.decoder.decode(BuildInfoResponse.self, from: res.data)
11-
}catch{
12-
throw.unexpectedResponse(res.data.prefix(1024))
13-
}
9+
returntrydecode(BuildInfoResponse.self, from: res.data)
1410
}
1511
}
1612

‎Coder Desktop/CoderSDK/User.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ public extension Client {
66
guard res.resp.statusCode==200else{
77
throwresponseAsError(res)
88
}
9-
do{
10-
returntryClient.decoder.decode(User.self, from: res.data)
11-
}catch{
12-
throw.unexpectedResponse(res.data.prefix(1024))
13-
}
9+
returntrydecode(User.self, from: res.data)
1410
}
1511
}
1612

@@ -25,9 +21,10 @@ public struct User: Encodable, Decodable, Equatable, Sendable {
2521
publicletlast_seen_at:Date
2622
publicletstatus:String
2723
publicletlogin_type:String
28-
publiclettheme_preference:String
2924
publicletorganization_ids:[UUID]
3025
publicletroles:[Role]
26+
// Deprecated and missing from responses as of Coder v2.21
27+
publiclettheme_preference:String?
3128

3229
publicinit(
3330
id:UUID,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp