Skip to content

Instantly share code, notes, and snippets.

@bharathreddys77
Last active May 23, 2021 08:01
Show Gist options
  • Save bharathreddys77/b7e0a810b002ce35bbbd7e0f2f3a01c6 to your computer and use it in GitHub Desktop.
Save bharathreddys77/b7e0a810b002ce35bbbd7e0f2f3a01c6 to your computer and use it in GitHub Desktop.
Create a network protocol which will be the blue print of all API methods. This file also has a network error Error type which provides possible fails of the API.
protocol NetworkingController {
func loginUser(request:LoginRequest,completion:@escaping(_ result:Result<LoginResponse,NetworkControllerError>) -> Void)
func forgotPassword(request:ForgotPasswordRequest,completion:@escaping(_ result:Result<ForgotPwdResponse,NetworkControllerError>) -> Void)
}
enum NetworkControllerError:Error {
case Non200StatusCodeError(NetworkError)
case NoNetworkError
case BadURLError
case UnParsableError
case UnknownError
case NoDataAvailableInResponseError
case customError(message:String)
}
struct NetworkError:Decodable {
let message:Bool?
let error:String?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment