-
Notifications
You must be signed in to change notification settings - Fork 107
/
errors.go
54 lines (46 loc) · 1.57 KB
/
errors.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
package stomp
import (
"github.com/go-stomp/stomp/frame"
)
// Error values
var (
ErrInvalidCommand = newErrorMessage("invalid command")
ErrInvalidFrameFormat = newErrorMessage("invalid frame format")
ErrUnsupportedVersion = newErrorMessage("unsupported version")
ErrCompletedTransaction = newErrorMessage("transaction is completed")
ErrNackNotSupported = newErrorMessage("NACK not supported in STOMP 1.0")
ErrNotReceivedMessage = newErrorMessage("cannot ack/nack a message, not from server")
ErrCannotNackAutoSub = newErrorMessage("cannot send NACK for a subscription with ack:auto")
ErrCompletedSubscription = newErrorMessage("subscription is unsubscribed")
ErrClosedUnexpectedly = newErrorMessage("connection closed unexpectedly")
ErrAlreadyClosed = newErrorMessage("connection already closed")
ErrNilOption = newErrorMessage("nil option")
)
// StompError implements the Error interface, and provides
// additional information about a STOMP error.
type Error struct {
Message string
Frame *frame.Frame
}
func (e Error) Error() string {
return e.Message
}
func missingHeader(name string) Error {
return newErrorMessage("missing header: " + name)
}
func newErrorMessage(msg string) Error {
return Error{Message: msg}
}
func newError(f *frame.Frame) Error {
e := Error{Frame: f}
if f.Command == frame.ERROR {
if message := f.Header.Get(frame.Message); message != "" {
e.Message = message
} else {
e.Message = "ERROR frame, missing message header"
}
} else {
e.Message = "Unexpected frame: " + f.Command
}
return e
}