Files
threshold/api/util.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

47 lines
827 B
Go

package api
import "github.com/fatih/structs"
func init() {
structs.DefaultTagName = "json"
}
// Bool returns the given bool as a bool pointer
func Bool(in bool) *bool {
ret := new(bool)
*ret = in
return ret
}
// String returns the given string as a string pointer
func String(in string) *string {
ret := new(string)
*ret = in
return ret
}
// StringOrNil is like String, but the returned pointer will be nil if the
// string is empty
func StringOrNil(in string) *string {
if in == "" {
return nil
}
return String(in)
}
// Int returns the given int64 as an int64 pointer
func Int(in int32) *int32 {
ret := new(int32)
*ret = in
return ret
}
// IntOrNil is like Int, but the returned pointer will be nil if the integer is
// 0
func IntOrNil(in int32) *int32 {
if in == 0 {
return nil
}
return Int(in)
}