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

Commita4ca27e

Browse files
committed
review
1 parentc9fbb1b commita4ca27e

File tree

4 files changed

+21
-26
lines changed

4 files changed

+21
-26
lines changed

‎Coder Desktop/Coder Desktop/Preview Content/PreviewClient.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import SwiftUI
2+
import Alamofire
23

34
structPreviewClient:Client{
45
init(url _:URL, token _:String?=nil){}
@@ -22,7 +23,7 @@ struct PreviewClient: Client {
2223
roles:[]
2324
)
2425
}catch{
25-
throwClientError.badResponse
26+
throwClientError.reqError(AFError.explicitlyCancelled)
2627
}
2728
}
2829
}

‎Coder Desktop/Coder Desktop/SDK/Client.swift

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,11 @@ struct CoderClient: Client {
3535
parameters: body,
3636
headers: headers
3737
).serializingData().response
38-
guardlet response= out.responseelse{
39-
throwClientError.noResponse
40-
}
4138
switch out.result{
4239
case.success(let data):
43-
returnHTTPResponse(resp: response, data: data, req: out.request)
44-
case.failure:
45-
throwClientError.badResponse
40+
returnHTTPResponse(resp:out.response!, data: data, req: out.request)
41+
case.failure(let error):
42+
throwClientError.reqError(error)
4643
}
4744
}
4845

@@ -57,28 +54,26 @@ struct CoderClient: Client {
5754
method: method,
5855
headers: headers
5956
).serializingData().response
60-
guardlet response= out.responseelse{
61-
throwClientError.noResponse
62-
}
6357
switch out.result{
6458
case.success(let data):
65-
returnHTTPResponse(resp: response, data: data, req: out.request)
66-
case.failure:
67-
throwClientError.badResponse
59+
returnHTTPResponse(resp:out.response!, data: data, req: out.request)
60+
case.failure(let error):
61+
throwClientError.reqError(error)
6862
}
6963
}
7064

71-
func responseAsError(_ resp:HTTPResponse)throws(ClientError)->APIError{
65+
func responseAsError(_ resp:HTTPResponse)->ClientError{
7266
do{
7367
letbody=tryCoderClient.decoder.decode(Response.self, from: resp.data)
74-
returnAPIError(
68+
letout=APIError(
7569
response: body,
7670
statusCode: resp.resp.statusCode,
7771
method: resp.req?.httpMethod,
7872
url: resp.req?.url
7973
)
74+
returnClientError.apiError(out)
8075
}catch{
81-
throwClientError.badResponse
76+
returnClientError.unexpectedResponse(resp.data[...1024])
8277
}
8378
}
8479

@@ -130,17 +125,17 @@ struct ValidationError: Decodable {
130125

131126
enumClientError:Error{
132127
case apiError(APIError)
133-
casebadResponse
134-
casenoResponse
128+
casereqError(AFError)
129+
caseunexpectedResponse(Data)
135130

136131
vardescription:String{
137132
switchself{
138133
case.apiError(let error):
139134
return error.description
140-
case.badResponse:
141-
return"Bad response"
142-
case.noResponse:
143-
return"No response"
135+
case.reqError(let error):
136+
returnerror.localizedDescription
137+
case.unexpectedResponse(let data):
138+
return"Unexpected response:\(data)"
144139
}
145140
}
146141
}

‎Coder Desktop/Coder Desktop/SDK/User.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ extension CoderClient {
44
func user(_ ident:String)asyncthrows(ClientError)->User{
55
letres=tryawaitrequest("/api/v2/users/\(ident)", method:.get)
66
guard res.resp.statusCode==200else{
7-
leterror=tryresponseAsError(res)
8-
throwClientError.apiError(error)
7+
throwresponseAsError(res)
98
}
109
do{
1110
returntryCoderClient.decoder.decode(User.self, from: res.data)
1211
}catch{
13-
throwClientError.badResponse
12+
throwClientError.unexpectedResponse(res.data[...1024])
1413
}
1514
}
1615
}

‎Coder Desktop/Coder DesktopTests/Util.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct MockClient: Client {
6969
structMockErrorClient:Client{
7070
init(url:URL, token:String?){}
7171
func user(_ ident:String)asyncthrows(ClientError)->Coder_Desktop.User{
72-
throwClientError.badResponse
72+
throwClientError.reqError(.explicitlyCancelled)
7373
}
7474
}
7575

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp