Skip to content

Commit

Permalink
Apparently Void is not Decodable
Browse files Browse the repository at this point in the history
  • Loading branch information
3lvis committed Jul 17, 2024
1 parent 9e91cff commit d86453a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Sources/Networking/Networking+HTTPRequests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@ public extension Networking {
return await handle(.put, path: path, parameters: parameters)
}

func newPut(_ path: String, parameters: [String: Any]) async -> Result<Void, NetworkingError> {
let result: Result<Data, NetworkingError> = await handle(.put, path: path, parameters: parameters)
switch result {
case .success:
return .success(())
case .failure(let error):
return .failure(error)
}
}

func newDelete(_ path: String) async -> Result<Void, NetworkingError> {
let result: Result<Data, NetworkingError> = await handle(.delete, path: path, parameters: nil)
switch result {
Expand Down
6 changes: 3 additions & 3 deletions Sources/Networking/Networking+New.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension Networking {
let result = try JSONResult(body: fakeRequest.response, response: response, error: error)
switch result {
case .success(let response):
if T.self == Void.self {
if T.self == Data.self {
logger.info("Successfully processed fake request to \(path, privacy: .public)")
return .success(() as! T)
} else {
Expand Down Expand Up @@ -47,8 +47,8 @@ extension Networking {
switch statusCode.statusCodeType {
case .informational, .successful:
logger.info("Received successful response with status code \(statusCode) from \(path, privacy: .public)")
if T.self == Void.self {
return .success(() as! T)
if T.self == Data.self {
return .success(Data() as! T)
} else if T.self == NetworkingResponse.self {
let headers = Dictionary(uniqueKeysWithValues: httpResponse.allHeaderFields.compactMap { key, value in
(key as? String).map { ($0, AnyCodable(value)) }
Expand Down

0 comments on commit d86453a

Please sign in to comment.