Files
threshold/api/error.gen.go
T
Todd Knight 44152ae63e Add API Error Handler (#74)
* Add error handler that converts from rpc.Status errors to Watchtower API errors.

* Better testing for ErrorHandler.

* Rename testcase and remove empty default switch case.

* Change the error status back to int64.

* Converting everything to int32s.

jsonpb wraps int64s as a string which we dont like.  We'll figure out how to use values larger than int64s when it comes up.

* Remove special casing for TraceId which isn't needed anymore.

* Removing wrappers from error details since we never need to know when they are set or unset from the end user.

* Using the helper error functions inside the project service.

* Correct usage of hclog, replace panic with Error log.

* Adding periods to all API returned errors, correct spelling, fix missed invalid argument error not using helper function.

* Change our logged errors to Error instead of Warn.

* Add TODO for defining and using our own defined API error codes.

* Add TODO to remove internal error messages.
2020-05-26 13:46:21 -07:00

44 lines
1.1 KiB
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 Error struct {
defaultFields []string
// The HTTP Status code applicable to this error
Status *int32 `json:"status,omitempty"`
// An application-specific error string
Code *string `json:"code,omitempty"`
// A human readable explanation specific to this occurrence of the error
Message *string `json:"message,omitempty"`
// Additional metadata regarding the error. Depending on the error
// different fields will be populated.
Details *ErrorDetails `json:"details,omitempty"`
}
func (s *Error) SetDefault(key string) {
s.defaultFields = strutil.AppendIfMissing(s.defaultFields, key)
}
func (s *Error) UnsetDefault(key string) {
s.defaultFields = strutil.StrListDelete(s.defaultFields, key)
}
func (s Error) 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)
}