@@ -50,7 +50,7 @@ func (m *Message) Parse() error {
50
50
cmr , err := m .tr .ReadMIMEHeader ()
51
51
52
52
if err != nil && err .Error () != "EOF" {
53
- Error ("Error while reading MIME headers: %s" , err )
53
+ Error (ECouldNotReadMIMEHeaders , err )
54
54
return err
55
55
}
56
56
@@ -65,14 +65,14 @@ func (m *Message) Parse() error {
65
65
l , err := strconv .Atoi (lv )
66
66
67
67
if err != nil {
68
- Error ("Unable to get size of content-length: %s" , err )
68
+ Error (EInvalidContentLength , err )
69
69
return err
70
70
}
71
71
72
72
m .Body = make ([]byte , l )
73
73
74
74
if _ , err := io .ReadFull (m .r , m .Body ); err != nil {
75
- Error ("Got error while reading reader body: %s" , err )
75
+ Error (ECouldNotReadyBody , err )
76
76
return err
77
77
}
78
78
}
@@ -82,7 +82,7 @@ func (m *Message) Parse() error {
82
82
Debug ("Got message content (type: %s). Searching if we can handle it ..." , msgType )
83
83
84
84
if ! StringInSlice (msgType , AvailableMessageTypes ) {
85
- return fmt .Errorf ("Unsupported message type! We got '%s'. Supported types are: %v " , msgType , AvailableMessageTypes )
85
+ return fmt .Errorf (EUnsupportedMessageType , msgType , AvailableMessageTypes )
86
86
}
87
87
88
88
// Assing message headers IF message is not type of event-json
@@ -96,7 +96,7 @@ func (m *Message) Parse() error {
96
96
m .Headers [k ], err = url .QueryUnescape (v [0 ])
97
97
98
98
if err != nil {
99
- Debug ( "Could not decode/unescape message: %s" , err )
99
+ Error ( ECouldNotDecode , err )
100
100
continue
101
101
}
102
102
}
@@ -111,12 +111,12 @@ func (m *Message) Parse() error {
111
111
case "command/reply" :
112
112
reply := cmr .Get ("Reply-Text" )
113
113
114
- if reply [: 2 ] == "-E" {
115
- return fmt .Errorf ("Got error while reading from reply command: %s" , reply [5 :])
114
+ if strings . Contains ( reply , "-ERR" ) {
115
+ return fmt .Errorf (EUnsuccessfulReply , reply [5 :])
116
116
}
117
117
case "api/response" :
118
- if string (m .Body [: 2 ]) == "-E" {
119
- return fmt .Errorf ("Got error while reading from reply command: %s" , string (m .Body )[5 :])
118
+ if strings . Contains ( string (m .Body ), "-ERR" ) {
119
+ return fmt .Errorf (EUnsuccessfulReply , string (m .Body )[5 :])
120
120
}
121
121
122
122
case "text/event-plain" :
@@ -127,21 +127,21 @@ func (m *Message) Parse() error {
127
127
emh , err := tr .ReadMIMEHeader ()
128
128
129
129
if err != nil {
130
- return fmt .Errorf ("Error while reading MIME headers (text/event-plain): %s" , err )
130
+ return fmt .Errorf (ECouldNotReadMIMEHeaders , err )
131
131
}
132
132
133
133
if vl := emh .Get ("Content-Length" ); vl != "" {
134
134
length , err := strconv .Atoi (vl )
135
135
136
136
if err != nil {
137
- Error ("Unable to get size of content-length (text/event-plain): %s" , err )
137
+ Error (EInvalidContentLength , err )
138
138
return err
139
139
}
140
140
141
141
m .Body = make ([]byte , length )
142
142
143
143
if _ , err = io .ReadFull (r , m .Body ); err != nil {
144
- Error ("Got error while reading body (text/event-plain): %s" , err )
144
+ Error (ECouldNotReadyBody , err )
145
145
return err
146
146
}
147
147
}
0 commit comments