Skip to content

Instantly share code, notes, and snippets.

@dinotrnka
Created January 16, 2023 19:07
Show Gist options
  • Save dinotrnka/249fea93c770e932d17a062562b3f6b7 to your computer and use it in GitHub Desktop.
Save dinotrnka/249fea93c770e932d17a062562b3f6b7 to your computer and use it in GitHub Desktop.
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