refactor: expose generated code and client business logic to share with Kapacitor (#103)
* refactor: take clients out of internal * refactor: move stdio to pkg * Move internal/api to api * refactor: final changes for Kapacitor to access shared functionality * chore: regenerate mocks * fix: bad automated refactor * chore: extra formatting not caught by make fmt
This commit is contained in:
45
api/error.go
Normal file
45
api/error.go
Normal file
@ -0,0 +1,45 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Extensions to let our API error types be used as "standard" errors.
|
||||
|
||||
func (o *Error) Error() string {
|
||||
if o.Message != "" && o.Err != nil {
|
||||
var b strings.Builder
|
||||
b.WriteString(o.Message)
|
||||
b.WriteString(": ")
|
||||
b.WriteString(*o.Err)
|
||||
return b.String()
|
||||
} else if o.Message != "" {
|
||||
return o.Message
|
||||
} else if o.Err != nil {
|
||||
return *o.Err
|
||||
}
|
||||
return fmt.Sprintf("<%s>", o.Code)
|
||||
}
|
||||
|
||||
func (o *HealthCheck) Error() string {
|
||||
if o.Status == HEALTHCHECKSTATUS_PASS {
|
||||
// Make sure we aren't misusing HealthCheck responses.
|
||||
panic("successful healthcheck used as an error!")
|
||||
}
|
||||
var message string
|
||||
if o.Message != nil {
|
||||
message = *o.Message
|
||||
} else {
|
||||
message = fmt.Sprintf("check %s failed", o.Name)
|
||||
}
|
||||
return fmt.Sprintf("health check failed: %s", message)
|
||||
}
|
||||
|
||||
func (o *LineProtocolError) Error() string {
|
||||
return o.Message
|
||||
}
|
||||
|
||||
func (o *LineProtocolLengthError) Error() string {
|
||||
return o.Message
|
||||
}
|
||||
Reference in New Issue
Block a user