Open Jberlinsky opened 3 years ago
Hey! This is a great call out.
We already have generated Error and ValidationError struct types.
We can make use of these types and json decode the error responses. To follow error conventions and not break downstream dependencies, we'd need to define a new Error struct that implements the error
interface .
Something like this:
type ResponseError struct {
StatusCode int
Error v4.Error
ValidationError v4.ValidationError
}
func (r *ResponseError) Error() string {
return fmt.Sprintf("...")
}
Though this would couple a custom Go SDK typing to our swagger spec. So not ideal, but also it's unlikely the swagger spec errors will change.
When issuing a request to the Golang API that triggers an HTTP 4XX error (e.g. a 422 validation error), the Swagger API will return useful error context, e.g.:
However, the Golang SDK doesn't seem to decode these error messages when a failure is encountered (see https://github.com/looker-open-source/sdk-codegen/blob/main/go/rtl/auth.go#L138). This leaves a user of the SDK in the unfortunate position of having to:
This also makes it difficult to write effective integration tests for erroneous states.