@@ -115,7 +115,7 @@ func WithOverloaded(rejectIfOverloaded bool) Options {
115
115
116
116
var defaultHandler = func (ctx context.Context , conn * Conn , req * Request ) {
117
117
if req .IsNotify () {
118
- conn .Reply (ctx , req , nil , Errorf (CodeMethodNotFound , "method %q not found" , req .Method ))
118
+ conn .Reply (ctx , req , nil , Errorf (MethodNotFound , "method %q not found" , req .Method ))
119
119
}
120
120
}
121
121
@@ -170,7 +170,7 @@ func (c *Conn) Notify(ctx context.Context, method string, params interface{}) er
170
170
c .Logger .Debug ("Notify" , zap .String ("method" , method ), zap .Any ("params" , params ))
171
171
p , err := c .marshalInterface (params )
172
172
if err != nil {
173
- return Errorf (CodeParseError , "failed to marshaling notify parameters: %v" , err )
173
+ return Errorf (ParseError , "failed to marshaling notify parameters: %v" , err )
174
174
}
175
175
176
176
req := & NotificationMessage {
@@ -180,7 +180,7 @@ func (c *Conn) Notify(ctx context.Context, method string, params interface{}) er
180
180
}
181
181
data , err := json .Marshal (req ) // TODO(zchee): use gojay
182
182
if err != nil {
183
- return Errorf (CodeParseError , "failed to marshaling notify request: %v" , err )
183
+ return Errorf (ParseError , "failed to marshaling notify request: %v" , err )
184
184
}
185
185
186
186
c .Logger .Debug (Send ,
@@ -190,7 +190,7 @@ func (c *Conn) Notify(ctx context.Context, method string, params interface{}) er
190
190
191
191
err = c .stream .Write (ctx , data )
192
192
if err != nil {
193
- return Errorf (CodeInternalError , "failed to write notify request data to steam: %v" , err )
193
+ return Errorf (InternalError , "failed to write notify request data to steam: %v" , err )
194
194
}
195
195
196
196
return nil
@@ -201,7 +201,7 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
201
201
c .Logger .Debug ("Call" , zap .String ("method" , method ), zap .Any ("params" , params ))
202
202
p , err := c .marshalInterface (params )
203
203
if err != nil {
204
- return Errorf (CodeParseError , "failed to marshaling call parameters: %v" , err )
204
+ return Errorf (ParseError , "failed to marshaling call parameters: %v" , err )
205
205
}
206
206
207
207
id := ID {Number : c .seq .Add (1 )}
@@ -215,7 +215,7 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
215
215
// marshal the request now it is complete
216
216
data , err := json .Marshal (req ) // TODO(zchee): use gojay
217
217
if err != nil {
218
- return Errorf (CodeParseError , "failed to marshaling call request: %v" , err )
218
+ return Errorf (ParseError , "failed to marshaling call request: %v" , err )
219
219
}
220
220
221
221
rchan := make (chan * Response )
@@ -237,7 +237,7 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
237
237
)
238
238
239
239
if err := c .stream .Write (ctx , data ); err != nil {
240
- return Errorf (CodeInternalError , "failed to write call request data to steam: %v" , err )
240
+ return Errorf (InternalError , "failed to write call request data to steam: %v" , err )
241
241
}
242
242
243
243
// wait for the response
@@ -258,7 +258,7 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
258
258
259
259
if err := json .Unmarshal (* resp .Result , result ); err != nil {
260
260
// if err := gojay.Unsafe.Unmarshal(*resp.Result, result); err != nil {
261
- return Errorf (CodeParseError , "failed to unmarshalling result: %v" , err )
261
+ return Errorf (ParseError , "failed to unmarshalling result: %v" , err )
262
262
}
263
263
264
264
return nil
@@ -275,7 +275,7 @@ func (c *Conn) Call(ctx context.Context, method string, params, result interface
275
275
func (c * Conn ) Reply (ctx context.Context , req * Request , result interface {}, err error ) error {
276
276
c .Logger .Debug ("Reply" )
277
277
if req .IsNotify () {
278
- return NewError (CodeInvalidRequest , "reply not invoked with a valid call" )
278
+ return NewError (InvalidRequest , "reply not invoked with a valid call" )
279
279
}
280
280
281
281
c .handlingMu .Lock ()
@@ -285,7 +285,7 @@ func (c *Conn) Reply(ctx context.Context, req *Request, result interface{}, err
285
285
}
286
286
c .handlingMu .Unlock ()
287
287
if ! found {
288
- return Errorf (CodeInternalError , "not a call in progress: %v" , req .ID )
288
+ return Errorf (InternalError , "not a call in progress: %v" , req .ID )
289
289
}
290
290
291
291
elapsed := time .Since (handling .start )
@@ -318,7 +318,7 @@ func (c *Conn) Reply(ctx context.Context, req *Request, result interface{}, err
318
318
zap .Any ("resp.Result" , resp .Result ),
319
319
zap .Error (err ),
320
320
)
321
- return Errorf (CodeParseError , "failed to marshaling reply response: %v" , err )
321
+ return Errorf (ParseError , "failed to marshaling reply response: %v" , err )
322
322
}
323
323
324
324
c .Logger .Debug (Send ,
@@ -330,7 +330,7 @@ func (c *Conn) Reply(ctx context.Context, req *Request, result interface{}, err
330
330
if err := c .stream .Write (ctx , data ); err != nil {
331
331
// TODO(iancottrell): if a stream write fails, we really need to shut down
332
332
// the whole stream
333
- return Errorf (CodeInternalError , "failed to write response data to steam: %v" , err )
333
+ return Errorf (InternalError , "failed to write response data to steam: %v" , err )
334
334
}
335
335
336
336
return nil
@@ -386,7 +386,7 @@ func (c *Conn) Run(ctx context.Context) (err error) {
386
386
// a badly formed message arrived, log it and continue
387
387
// we trust the stream to have isolated the error to just this message
388
388
c .Logger .Debug (Receive ,
389
- zap .Error (Errorf (CodeParseError , "unmarshal failed: %v" , err )),
389
+ zap .Error (Errorf (ParseError , "unmarshal failed: %v" , err )),
390
390
)
391
391
continue
392
392
}
@@ -429,7 +429,7 @@ func (c *Conn) Run(ctx context.Context) (err error) {
429
429
430
430
if ! c .deliver (ctxReq , queuec , req ) {
431
431
// queue is full, reject the message by directly replying
432
- c .Reply (ctx , req , nil , Errorf (CodeServerOverloaded , "no room in queue" ))
432
+ c .Reply (ctx , req , nil , Errorf (ServerOverloaded , "no room in queue" ))
433
433
}
434
434
}
435
435
@@ -453,7 +453,7 @@ func (c *Conn) Run(ctx context.Context) (err error) {
453
453
close (rchan ) // for the range channel loop
454
454
455
455
default :
456
- c .Logger .Warn (Receive , zap .Error (NewError (CodeInvalidParams , "ignoring because message not a call, notify or response" )))
456
+ c .Logger .Warn (Receive , zap .Error (NewError (InvalidParams , "ignoring because message not a call, notify or response" )))
457
457
}
458
458
}
459
459
}
0 commit comments