* Invalid Argument errors now return a per field error message. * Creating an API error struct. * SDK uses field error details proto. * Adding tests specifically for handler helper error messages resulting in expected API output. * Inlining the error checks into the table driven tests. Use protocmp for assertions to make printing out diffs easier to parse. * Aggregate the invalid argument fields detected to be wrong. * Make the returned order of fields deterministic in the error details.. * Fixing formatting issue in errors_test.go. * Test to confirm unimplemented results in a 405 and not 404.
38 lines
846 B
Go
38 lines
846 B
Go
// Code generated by "make api"; DO NOT EDIT.
|
|
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/fatih/structs"
|
|
|
|
"github.com/hashicorp/watchtower/api/internal/strutil"
|
|
)
|
|
|
|
type ErrorDetails struct {
|
|
defaultFields []string
|
|
|
|
TraceId *string `json:"TraceId,omitempty"`
|
|
RequestId *string `json:"request_id,omitempty"`
|
|
RequestFields []*FieldError `json:"request_fields,omitempty"`
|
|
}
|
|
|
|
func (s *ErrorDetails) SetDefault(key string) {
|
|
s.defaultFields = strutil.AppendIfMissing(s.defaultFields, key)
|
|
}
|
|
|
|
func (s *ErrorDetails) UnsetDefault(key string) {
|
|
s.defaultFields = strutil.StrListDelete(s.defaultFields, key)
|
|
}
|
|
|
|
func (s ErrorDetails) MarshalJSON() ([]byte, error) {
|
|
m := structs.Map(s)
|
|
if m == nil {
|
|
m = make(map[string]interface{})
|
|
}
|
|
for _, k := range s.defaultFields {
|
|
m[k] = nil
|
|
}
|
|
return json.Marshal(m)
|
|
}
|