feat(api): improve codegen outputs (#41)
* Use `[]byte` for generated request bodies when the source schema has `format: byte` * Gzip-compress request bodies when `Content-Encoding: gzip` is set * Require that all models returned as error conditions in our API implement the `error` interface * Move the implementation for `api.HealthCheck` out of `ping.go` and into `api/error.go` Co-authored-by: William Baker <55118525+wbaker85@users.noreply.github.com>
This commit is contained in:
@ -5,7 +5,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Extension to let our API error type be used as a "standard" error.
|
||||
// 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
|
||||
@ -20,3 +21,17 @@ func (o *Error) Error() string {
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
Reference in New Issue
Block a user