handle error message
This commit is contained in:
parent
7adf624dca
commit
332ff6f40b
@ -349,7 +349,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
|
||||
|
||||
public func open(opts:[String: AnyObject]? = nil) {
|
||||
if self.connected {
|
||||
self.client?.engineDidError("Engine tried to open while connected")
|
||||
self.client?.didError("Engine tried to open while connected")
|
||||
return
|
||||
}
|
||||
|
||||
@ -478,9 +478,8 @@ public class SocketEngine: NSObject, WebSocketDelegate {
|
||||
message.removeAtIndex(message.startIndex)
|
||||
let mesData = message.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
|
||||
|
||||
if let json = NSJSONSerialization.JSONObjectWithData(mesData,
|
||||
options: NSJSONReadingOptions.AllowFragments, error: &err) as? NSDictionary,
|
||||
let sid = json["sid"] as? String {
|
||||
if let json = NSJSONSerialization.JSONObjectWithData(mesData, options: NSJSONReadingOptions.AllowFragments,
|
||||
error: &err) as? NSDictionary, let sid = json["sid"] as? String {
|
||||
self.sid = sid
|
||||
self._connected = true
|
||||
|
||||
@ -492,7 +491,7 @@ public class SocketEngine: NSObject, WebSocketDelegate {
|
||||
self.pingInterval = pingInterval / 1000
|
||||
}
|
||||
} else {
|
||||
self.client?.engineDidError("Engine failed to handshake")
|
||||
self.client?.didError("Engine failed to handshake")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ import Foundation
|
||||
var socketURL:String {get}
|
||||
var secure:Bool {get}
|
||||
|
||||
func engineDidError(reason:String)
|
||||
func didError(reason:AnyObject)
|
||||
func engineDidForceClose(reason:String)
|
||||
func parseSocketMessage(msg:String)
|
||||
func parseBinaryData(data:NSData)
|
||||
|
||||
@ -226,6 +226,15 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
||||
self.handleEvent("connect", data: nil, isInternalMessage: false)
|
||||
}
|
||||
|
||||
/// error
|
||||
public func didError(reason:AnyObject) {
|
||||
if !(reason is [AnyObject]) {
|
||||
self.handleEvent("error", data: [reason], isInternalMessage: true)
|
||||
} else {
|
||||
self.handleEvent("error", data: reason as? [AnyObject], isInternalMessage: true)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Same as close
|
||||
*/
|
||||
@ -321,11 +330,6 @@ public class SocketIOClient: NSObject, SocketEngineClient {
|
||||
}
|
||||
}
|
||||
|
||||
/// Engine error
|
||||
public func engineDidError(reason:String) {
|
||||
self.handleEvent("error", data: [reason], isInternalMessage: true)
|
||||
}
|
||||
|
||||
/// Server wants us to die
|
||||
public func engineDidForceClose(reason:String) {
|
||||
if self.closed {
|
||||
|
||||
@ -144,11 +144,16 @@ class SocketParser {
|
||||
id = c.toInt()
|
||||
}
|
||||
|
||||
if i + 1 < arr.count {
|
||||
let d = String(arr[++i...arr.count-1])
|
||||
if ++i < arr.count {
|
||||
let d = String(arr[i...arr.count-1])
|
||||
let noPlaceholders = d["(\\{\"_placeholder\":true,\"num\":(\\d*)\\})"] ~= "\"~~$2\""
|
||||
let data:[AnyObject]
|
||||
|
||||
let data = SocketParser.parseData(noPlaceholders) as! [AnyObject]
|
||||
if let isArr = SocketParser.parseData(noPlaceholders) as? [AnyObject] {
|
||||
data = isArr
|
||||
} else {
|
||||
data = [noPlaceholders]
|
||||
}
|
||||
|
||||
return SocketPacket(type: SocketPacketType(str: type), data: data,
|
||||
nsp: nsp, placeholders: placeholders, id: id)
|
||||
@ -224,6 +229,8 @@ class SocketParser {
|
||||
}
|
||||
} else if p.type == SocketPacketType.DISCONNECT {
|
||||
socket.engineDidForceClose("Got Disconnect")
|
||||
} else if p.type == SocketPacketType.ERROR {
|
||||
socket.didError(p.data == nil ? "Error" : p.data!)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user