Add timeout error
This commit is contained in:
parent
77b1a25faf
commit
45c05c4e2b
@ -132,7 +132,7 @@ func (r *rpcClient) call(ctx context.Context, address string, req Request, resp
|
|||||||
return err
|
return err
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
grr = ctx.Err()
|
grr = ctx.Err()
|
||||||
return errors.New("go.micro.client", fmt.Sprintf("request timeout: %v", ctx.Err()), 408)
|
return errors.Timeout("go.micro.client", fmt.Sprintf("%v", ctx.Err()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -192,7 +192,7 @@ func (r *rpcClient) stream(ctx context.Context, address string, req Request, opt
|
|||||||
case err := <-ch:
|
case err := <-ch:
|
||||||
grr = err
|
grr = err
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
grr = errors.New("go.micro.client", fmt.Sprintf("request timeout: %v", ctx.Err()), 408)
|
grr = errors.Timeout("go.micro.client", fmt.Sprintf("%v", ctx.Err()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if grr != nil {
|
if grr != nil {
|
||||||
@ -274,7 +274,7 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
|
|||||||
// should we noop right here?
|
// should we noop right here?
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return errors.New("go.micro.client", fmt.Sprintf("%v", ctx.Err()), 408)
|
return errors.Timeout("go.micro.client", fmt.Sprintf("%v", ctx.Err()))
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ func (r *rpcClient) Call(ctx context.Context, request Request, response interfac
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return errors.New("go.micro.client", fmt.Sprintf("call timeout: %v", ctx.Err()), 408)
|
return errors.Timeout("go.micro.client", fmt.Sprintf("call timeout: %v", ctx.Err()))
|
||||||
case err := <-ch:
|
case err := <-ch:
|
||||||
// if the call succeeded lets bail early
|
// if the call succeeded lets bail early
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -367,7 +367,7 @@ func (r *rpcClient) Stream(ctx context.Context, request Request, opts ...CallOpt
|
|||||||
// should we noop right here?
|
// should we noop right here?
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, errors.New("go.micro.client", fmt.Sprintf("%v", ctx.Err()), 408)
|
return nil, errors.Timeout("go.micro.client", fmt.Sprintf("%v", ctx.Err()))
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,7 +416,7 @@ func (r *rpcClient) Stream(ctx context.Context, request Request, opts ...CallOpt
|
|||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, errors.New("go.micro.client", fmt.Sprintf("call timeout: %v", ctx.Err()), 408)
|
return nil, errors.Timeout("go.micro.client", fmt.Sprintf("call timeout: %v", ctx.Err()))
|
||||||
case rsp := <-ch:
|
case rsp := <-ch:
|
||||||
// if the call succeeded lets bail early
|
// if the call succeeded lets bail early
|
||||||
if rsp.err == nil {
|
if rsp.err == nil {
|
||||||
|
@ -92,13 +92,13 @@ func MethodNotAllowed(id, format string, a ...interface{}) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// InternalServerError generates a 500 error.
|
// Timeout generates a 408 error.
|
||||||
func InternalServerError(id, format string, a ...interface{}) error {
|
func Timeout(id, format string, a ...interface{}) error {
|
||||||
return &Error{
|
return &Error{
|
||||||
Id: id,
|
Id: id,
|
||||||
Code: 500,
|
Code: 408,
|
||||||
Detail: fmt.Sprintf(format, a...),
|
Detail: fmt.Sprintf(format, a...),
|
||||||
Status: http.StatusText(500),
|
Status: http.StatusText(408),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,3 +111,13 @@ func Conflict(id, format string, a ...interface{}) error {
|
|||||||
Status: http.StatusText(409),
|
Status: http.StatusText(409),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// InternalServerError generates a 500 error.
|
||||||
|
func InternalServerError(id, format string, a ...interface{}) error {
|
||||||
|
return &Error{
|
||||||
|
Id: id,
|
||||||
|
Code: 500,
|
||||||
|
Detail: fmt.Sprintf(format, a...),
|
||||||
|
Status: http.StatusText(500),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user