1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19 
20 public struct TTransportError: TError {
21   public enum ErrorCode: TErrorCode {
22     case unknown
23     case notOpen
24     case alreadyOpen
25     case timedOut
26     case endOfFile
27     case negativeSize
28     case sizeLimit(limit: Int, got: Int)
29 
30     public var thriftErrorCode: Int {
31       switch self {
32       case .unknown:      return 0
33       case .notOpen:      return 1
34       case .alreadyOpen:  return 2
35       case .timedOut:     return 3
36       case .endOfFile:    return 4
37       case .negativeSize: return 5
38       case .sizeLimit:    return 6
39       }
40     }
41     public var description: String {
42       switch self {
43       case .unknown:      return "Unknown TTransportError"
44       case .notOpen:      return "Not Open"
45       case .alreadyOpen:  return "Already Open"
46       case .timedOut:     return "Timed Out"
47       case .endOfFile:    return "End Of File"
48       case .negativeSize: return "Negative Size"
49       case .sizeLimit(let limit, let got):
50         return "Message exceeds size limit of \(limit) (received: \(got)"
51       }
52     }
53   }
54   public var error: ErrorCode = .unknown
55   public var message: String? = nil
56   public static var defaultCase: ErrorCode { return .unknown }
57 
58   public init() { }
59 
60 }
61 
62 /// THTTPTransportError
63 ///
64 /// Error's thrown on HTTP Transport
65 public struct THTTPTransportError: TError {
66   public enum ErrorCode: TErrorCode {
67     case invalidResponse
68     case invalidStatus(statusCode: Int)
69     case authentication
70 
71     public var description: String {
72       switch self {
73       case .invalidResponse:                return "Invalid HTTP Response"
74       case .invalidStatus(let statusCode):  return "Invalid HTTP Status Code (\(statusCode))"
75       case .authentication:                 return "Authentication Error"
76       }
77     }
78     public var thriftErrorCode: Int { return 0 }
79   }
80   public var error: ErrorCode = .invalidResponse
81   public var message: String? = nil
82   public static var defaultCase: ErrorCode { return .invalidResponse }
83 
84   public init() { }
85 }
86 
87