Skip to content

Instantly share code, notes, and snippets.

@cumanzor
Created December 16, 2017 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cumanzor/668081833cdef324baa1e3743a3154d1 to your computer and use it in GitHub Desktop.
Save cumanzor/668081833cdef324baa1e3743a3154d1 to your computer and use it in GitHub Desktop.
localizable error types
// avoid the whole switch error type set description pattern we were using before (unless custom actions need to be attached or something)
// see: https://stackoverflow.com/questions/39176196/how-to-provide-a-localized-description-with-an-error-type-in-swift
import Foundation
public enum customError:Error{
case NONETWORK
case INVALIDJSON
case UNEXPECTEDRESPONSE
case INVALIDCREDENTIALS
case Other(String?)
}
extension customError: LocalizedError {
public var errorDescription: String? {
switch self {
case .NONETWORK:
return NSLocalizedString("No hay conexión al servidor.", comment: "Sin conectividad")
case .INVALIDJSON, .UNEXPECTEDRESPONSE:
return NSLocalizedString("Respuesta del servidor invalida.", comment: "El servidor ha retornado una respuesta invalida.")
case .INVALIDCREDENTIALS:
return NSLocalizedString("El usuario o contraseña son incorrectos", comment: "Autorización Invalida")
case .Other(let s):
return s!
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment