Jens Geyer | 0e87c46 | 2013-06-18 22:25:07 +0200 | [diff] [blame^] | 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 | package thrift |
| 21 | |
| 22 | import ( |
| 23 | "io" |
| 24 | ) |
| 25 | |
| 26 | // Thrift Transport exception |
| 27 | type TTransportException interface { |
| 28 | TException |
| 29 | TypeId() int |
| 30 | } |
| 31 | |
| 32 | const ( |
| 33 | UNKNOWN_TRANSPORT_EXCEPTION = 0 |
| 34 | NOT_OPEN = 1 |
| 35 | ALREADY_OPEN = 2 |
| 36 | TIMED_OUT = 3 |
| 37 | END_OF_FILE = 4 |
| 38 | ) |
| 39 | |
| 40 | type tTransportException struct { |
| 41 | typeId int |
| 42 | message string |
| 43 | } |
| 44 | |
| 45 | func (p *tTransportException) TypeId() int { |
| 46 | return p.typeId |
| 47 | } |
| 48 | |
| 49 | func (p *tTransportException) Error() string { |
| 50 | return p.message |
| 51 | } |
| 52 | |
| 53 | func NewTTransportException(t int, m string) TTransportException { |
| 54 | return &tTransportException{typeId: t, message: m} |
| 55 | } |
| 56 | |
| 57 | func NewTTransportExceptionFromError(e error) TTransportException { |
| 58 | if e == nil { |
| 59 | return nil |
| 60 | } |
| 61 | if t, ok := e.(TTransportException); ok { |
| 62 | return t |
| 63 | } |
| 64 | if e == io.EOF { |
| 65 | return NewTTransportException(END_OF_FILE, e.Error()) |
| 66 | } |
| 67 | return NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, e.Error()) |
| 68 | } |