@@ -2,54 +2,58 @@ package ws
2
2
3
3
// RejectOption represents an option used to control the way connection is
4
4
// rejected.
5
- type RejectOption func (* rejectConnectionError )
5
+ type RejectOption func (* ConnectionRejectedError )
6
6
7
7
// RejectionReason returns an option that makes connection to be rejected with
8
8
// given reason.
9
9
func RejectionReason (reason string ) RejectOption {
10
- return func (err * rejectConnectionError ) {
10
+ return func (err * ConnectionRejectedError ) {
11
11
err .reason = reason
12
12
}
13
13
}
14
14
15
15
// RejectionStatus returns an option that makes connection to be rejected with
16
16
// given HTTP status code.
17
17
func RejectionStatus (code int ) RejectOption {
18
- return func (err * rejectConnectionError ) {
18
+ return func (err * ConnectionRejectedError ) {
19
19
err .code = code
20
20
}
21
21
}
22
22
23
23
// RejectionHeader returns an option that makes connection to be rejected with
24
24
// given HTTP headers.
25
25
func RejectionHeader (h HandshakeHeader ) RejectOption {
26
- return func (err * rejectConnectionError ) {
26
+ return func (err * ConnectionRejectedError ) {
27
27
err .header = h
28
28
}
29
29
}
30
30
31
- // RejectConnectionError constructs an error that could be used to control the way
32
- // handshake is rejected by Upgrader.
31
+ // RejectConnectionError constructs an error that could be used to control the
32
+ // way handshake is rejected by Upgrader.
33
33
func RejectConnectionError (options ... RejectOption ) error {
34
- err := new (rejectConnectionError )
34
+ err := new (ConnectionRejectedError )
35
35
for _ , opt := range options {
36
36
opt (err )
37
37
}
38
38
return err
39
39
}
40
40
41
- // rejectConnectionError represents a rejection of connection during WebSocket
42
- // handshake error.
41
+ // ConnectionRejectedError represents a rejection of connection during
42
+ // WebSocket handshake error.
43
43
//
44
- // It can be returned by Upgrader's On* hooks to control the way WebSocket
45
- // handshake is rejected.
46
- type rejectConnectionError struct {
44
+ // It can be returned by Upgrader's On* hooks to indicate that WebSocket
45
+ // handshake should be rejected.
46
+ type ConnectionRejectedError struct {
47
47
reason string
48
48
code int
49
49
header HandshakeHeader
50
50
}
51
51
52
52
// Error implements error interface.
53
- func (r * rejectConnectionError ) Error () string {
53
+ func (r * ConnectionRejectedError ) Error () string {
54
54
return r .reason
55
55
}
56
+
57
+ func (r * ConnectionRejectedError ) StatusCode () int {
58
+ return r .code
59
+ }
0 commit comments