-
Notifications
You must be signed in to change notification settings - Fork 30
/
Errors.swift
49 lines (37 loc) · 1.23 KB
/
Errors.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//
// Errors.swift
// Buildasaur
//
// Created by Honza Dvorsky on 07/03/2015.
// Copyright (c) 2015 Honza Dvorsky. All rights reserved.
//
import Foundation
public enum BuildaError: String {
case UnknownError = "Unknown error"
}
public struct Error {
public static func fromType(type: BuildaError) -> NSError {
return self.withInfo(type.rawValue)
}
public static func withInfo(info: String?, internalError: NSError? = nil, userInfo: NSDictionary? = nil) -> NSError {
let finalInfo = NSMutableDictionary()
if let info = info {
finalInfo[NSLocalizedDescriptionKey] = info
}
if let internalError = internalError {
finalInfo["encountered_error"] = internalError
}
if let userInfo = userInfo {
finalInfo.addEntriesFromDictionary(userInfo as [NSObject : AnyObject])
}
return NSError(domain: "com.honzadvorsky.Buildasaur", code: 0, userInfo: finalInfo as [NSObject : AnyObject])
}
}
struct StringError: ErrorType {
let description: String
let _domain: String = ""
let _code: Int = 0
init(_ description: String) {
self.description = description
}
}