Skip to content

Instantly share code, notes, and snippets.

@shishirthedev
Created May 5, 2019 04:36
Show Gist options
  • Save shishirthedev/351473dd5cff03dc5dfe49ce5c1910c6 to your computer and use it in GitHub Desktop.
Save shishirthedev/351473dd5cff03dc5dfe49ce5c1910c6 to your computer and use it in GitHub Desktop.
import UIKit
class ErrorHandler {
private init(){}
static var view: NetworkViewProtocol?
static func handleError(httpSatusCode: Int?, error: Error?){
if let httpCode = httpSatusCode{
switch httpCode{
case NOT_FOUND:
view?.onServerError(errorMSG: "NOT FOUND")
break
case UNAUTHORIZED:
view?.onUnauthorized(unAuthorizedMSG: "UNAUTHORIZED USER")
break
case INTERNEL_SERVER_ERROR:
view?.onServerError(errorMSG: "INTERNAL SERVER ERROR")
break
default:
print("FAILED")
}
}else if let error = error as NSError?{
if error == NSError.NO_INTERNET{
view?.networkUnavailable()
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment