| 1 |
package status |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
|
| 6 |
"github.com/influxdata/yarpc/codes" |
| 7 |
) |
| 8 |
|
| 9 |
func (m *Status) Error() string { |
| 10 |
return fmt.Sprintf("rpc error: code = %s desc = %s", m.Code, m.Message) |
| 11 |
} |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
func FromError(err error) (s *Status, ok bool) { |
| 16 |
if err == nil { |
| 17 |
return &Status{Code: codes.OK}, true |
| 18 |
} |
| 19 |
if s, ok := err.(*Status); ok { |
| 20 |
return s, true |
| 21 |
} |
| 22 |
return nil, false |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
func Errorf(c codes.Code, format string, a ...interface{}) error { |
| 27 |
return &Status{Code: c, Message: fmt.Sprintf(format, a...)} |
| 28 |
} |