Created
January 16, 2023 19:07
-
-
Save dinotrnka/249fea93c770e932d17a062562b3f6b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
struct LoginAction { | |
let path = "/login" | |
let method: HTTPMethod = .post | |
var parameters: LoginRequest | |
func call( | |
completion: @escaping (LoginResponse) -> Void, | |
failure: @escaping (APIError) -> Void // Added this | |
) { | |
APIRequest<LoginRequest, LoginResponse>.call( | |
path: path, | |
method: .post, | |
parameters: parameters | |
) { data in | |
if let response = try? JSONDecoder().decode( | |
LoginResponse.self, | |
from: data | |
) { | |
completion(response) | |
} else { | |
failure(.jsonDecoding) // Added this | |
} | |
} failure: { error in | |
failure(error) // Added this | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment