From c8d389c765fb28a5342715cfeb4c11e0cb3e8d0c Mon Sep 17 00:00:00 2001 From: Andrew Visotskiy Date: Sat, 26 Nov 2016 13:54:35 +0200 Subject: [PATCH] bugfixes --- JSTP.podspec | 2 +- JSTP/Errors.swift | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/JSTP.podspec b/JSTP.podspec index 947a261..bdc989e 100644 --- a/JSTP.podspec +++ b/JSTP.podspec @@ -1,7 +1,7 @@ Pod::Spec.new do |s| s.name = 'JSTP' - s.version = '0.1.9' + s.version = '0.1.9.1' s.license = { :type => "MIT" } s.homepage = 'https://github.com/metarhia/JSTP' diff --git a/JSTP/Errors.swift b/JSTP/Errors.swift index 1e7de99..5efa062 100644 --- a/JSTP/Errors.swift +++ b/JSTP/Errors.swift @@ -18,16 +18,21 @@ internal extension NSError { internal convenience init?(_ object: Any) { + guard let data = object as? [Any], + let code = data[0] as? Int else { - guard let data = object as? [Any], - let code = data[0] as? Int, - let description = data[1] as? String else { - return nil } + + var description: String! - self.init(code, description) + if data.count == 2 { + description = data[1] as? String + } + description = description ?? Errors.kErrors[code] ?? "Undefined error" + + self.init(code, description) } internal func raw() -> AnyObject { @@ -49,6 +54,19 @@ open class Errors { open static let ApplicationNotFound = NSError(10, "Application not found" ) open static let AuthorizationFailed = NSError(11, "Authentication failed" ) open static let InterfaceNotFound = NSError(12, "Interface not found" ) + open static let InternalError = NSError(16, "Internal API error" ) open static let MethodNotFound = NSError(14, "Method not found" ) + open static let NotSerever = NSError(15, "Not a server" ) + + fileprivate static let kErrors = [ + + 13: "Incompatible interface", + 10: "Application not found", + 11: "Authentication failed", + 12: "Interface not found", + 16: "Internal API error", + 14: "Method not found", + 15: "Not a server", + ] + } -