Files
Xaibatsu-Control-Panel/XIONControlPanel/Utilities/NSErrorAdditions.swift

57 lines
1.2 KiB
Swift
Raw Normal View History

//
// NSErrorAdditions.swift
// XIONControlPanel
//
// Created by Charles Magahern on 12/31/15.
// Copyright © 2015 XION. All rights reserved.
//
import Foundation
2016-07-24 00:14:04 -07:00
enum XIONErrorCode: Int
{
2017-05-13 00:40:03 -07:00
case unknown
case connectionError
}
struct XIONError : Error
{
enum ErrorCode
{
case unknown
case connectionError
}
}
2016-07-24 00:14:04 -07:00
extension NSError
{
2017-05-13 00:40:03 -07:00
fileprivate static let XIONErrorDomain = "com.xionsf.controlpanel"
2017-05-13 00:40:03 -07:00
class func xionError(_ code: XIONErrorCode) -> NSError
{
return self.xionError(code, userInfo: nil)
}
2017-05-13 00:40:03 -07:00
class func xionError(_ code: XIONErrorCode, underlying: NSError?) -> NSError
{
2017-05-13 00:40:03 -07:00
var userInfo: [AnyHashable: Any]? = nil
if (underlying != nil) {
userInfo = [
NSUnderlyingErrorKey : underlying!
]
}
return self.xionError(code, userInfo: userInfo)
}
2017-05-13 00:40:03 -07:00
class func xionError(_ code: XIONErrorCode, userInfo: [AnyHashable: Any]?) -> NSError
{
2019-09-24 22:17:16 -07:00
return NSError(domain: XIONErrorDomain, code: code.rawValue, userInfo: userInfo as? [String : Any])
}
var xionErrorCode: XIONErrorCode
{
return XIONErrorCode(rawValue: self.code)!
}
}