Skip to content

Commit

Permalink
fix: use correct encoding on http response bodys
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomatree committed Aug 22, 2024
1 parent 19170b9 commit d4894aa
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions Revolt/Api/Http.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,18 @@ struct HTTPClient {
headers: HTTPHeaders? = nil
) async -> Result<O, RevoltError> {
return await innerReq(method: method, route: route, parameters: parameters, encoder: encoder, headers: headers).flatMap { response in
response.result
.mapError(RevoltError.Alamofire)
.flatMap {
do {
return .success(try JSONDecoder().decode(O.self, from: $0.data(using: .utf8)!))
} catch {
return .failure(.JSONDecoding(error))
}
if let error = response.error {
return .failure(.Alamofire(error))
} else if let data = response.data {
do {
return .success(try JSONDecoder().decode(O.self, from: data))
} catch {
return .failure(.JSONDecoding(error))
}

} else {
return .failure(.HTTPError("No error or body", 0))
}
}
}

Expand All @@ -106,9 +109,11 @@ struct HTTPClient {
headers: HTTPHeaders? = nil
) async -> Result<EmptyResponse, RevoltError> {
return await innerReq(method: method, route: route, parameters: parameters, encoder: encoder, headers: headers).flatMap { response in
response.result
.mapError(RevoltError.Alamofire)
.map { _ in EmptyResponse() }
if let error = response.error {
return .failure(.Alamofire(error))
} else {
return .success(EmptyResponse())
}
}
}

Expand Down

0 comments on commit d4894aa

Please sign in to comment.