-
-
Notifications
You must be signed in to change notification settings - Fork 384
Expand file tree
/
Copy pathTrinoError.swift
More file actions
57 lines (52 loc) · 1.75 KB
/
Copy pathTrinoError.swift
File metadata and controls
57 lines (52 loc) · 1.75 KB
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
50
51
52
53
54
55
56
57
import Foundation
public struct TrinoQueryError: Decodable, Sendable, Equatable {
public let message: String
public let errorCode: Int?
public let errorName: String?
public let errorType: String?
public init(message: String, errorCode: Int? = nil, errorName: String? = nil, errorType: String? = nil) {
self.message = message
self.errorCode = errorCode
self.errorName = errorName
self.errorType = errorType
}
private enum CodingKeys: String, CodingKey {
case message, errorCode, errorName, errorType
}
}
public enum TrinoError: Error, LocalizedError, Equatable {
case invalidConfiguration(String)
case notConnected
case transport(String)
case httpStatus(code: Int, body: String)
case authenticationFailed(String)
case query(TrinoQueryError)
case invalidResponse(String)
case cancelled
case timedOut
public var errorDescription: String? {
switch self {
case .invalidConfiguration(let detail):
return detail
case .notConnected:
return "Not connected to Trino"
case .transport(let detail):
return detail
case .httpStatus(let code, let body):
return body.isEmpty ? "HTTP \(code)" : "HTTP \(code): \(body)"
case .authenticationFailed(let detail):
return detail
case .query(let error):
if let name = error.errorName, !name.isEmpty {
return "\(name): \(error.message)"
}
return error.message
case .invalidResponse(let detail):
return detail
case .cancelled:
return "Query was cancelled"
case .timedOut:
return "Timed out waiting for Trino"
}
}
}