Files

57 lines
1.2 KiB
Swift
Raw Permalink Normal View History

2015-12-31 19:51:51 -08:00
//
// 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
}
2015-12-31 19:51:51 -08:00
}
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"
2015-12-31 19:51:51 -08:00
2017-05-13 00:40:03 -07:00
class func xionError(_ code: XIONErrorCode) -> NSError
2015-12-31 19:51:51 -08:00
{
return self.xionError(code, userInfo: nil)
}
2017-05-13 00:40:03 -07:00
class func xionError(_ code: XIONErrorCode, underlying: NSError?) -> NSError
2015-12-31 19:51:51 -08:00
{
2017-05-13 00:40:03 -07:00
var userInfo: [AnyHashable: Any]? = nil
2015-12-31 19:51:51 -08:00
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
2015-12-31 19:51:51 -08:00
{
2019-09-24 22:17:16 -07:00
return NSError(domain: XIONErrorDomain, code: code.rawValue, userInfo: userInfo as? [String : Any])
2015-12-31 19:51:51 -08:00
}
var xionErrorCode: XIONErrorCode
{
return XIONErrorCode(rawValue: self.code)!
}
}