-
Notifications
You must be signed in to change notification settings - Fork 14
/
error.go
66 lines (52 loc) · 1.61 KB
/
error.go
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
58
59
60
61
62
63
64
65
66
// Copyright 2015 The GoTor Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
type ErrorHandleMethod byte
const (
_ = iota
ERROR_CLOSE_CONNECTION ErrorHandleMethod = iota
ERROR_CLOSE_CIRCUIT
ERROR_CLOSE_STREAM
ERROR_REFUSE_CIRCUIT
ERROR_REFUSE_STREAM
)
type ActionableError interface {
error
Handle() ErrorHandleMethod
CircDestroyReason() DestroyReason
StreamEndReason() StreamEndReason
}
type wrappedError struct {
wrappedError error
handleType ErrorHandleMethod
circDestroyReason DestroyReason
streamEndReason StreamEndReason
}
func (e *wrappedError) Handle() ErrorHandleMethod {
return e.handleType
}
func (e *wrappedError) Error() string {
return e.wrappedError.Error()
}
func (e *wrappedError) CircDestroyReason() DestroyReason {
return e.circDestroyReason
}
func (e *wrappedError) StreamEndReason() StreamEndReason {
return e.streamEndReason
}
func CloseCircuit(e error, reason DestroyReason) ActionableError {
return &wrappedError{e, ERROR_CLOSE_CIRCUIT, reason, 0}
}
func RefuseCircuit(e error, reason DestroyReason) ActionableError {
return &wrappedError{e, ERROR_REFUSE_CIRCUIT, reason, 0}
}
func CloseConnection(e error) ActionableError {
return &wrappedError{e, ERROR_CLOSE_CONNECTION, 0, 0}
}
func CloseStream(e error, reason StreamEndReason) ActionableError {
return &wrappedError{e, ERROR_CLOSE_STREAM, 0, reason}
}
func RefuseStream(e error, reason StreamEndReason) ActionableError {
return &wrappedError{e, ERROR_REFUSE_STREAM, 0, reason}
}