MCPcopy Index your code
hub / github.com/CyCoreSystems/ari-proxy / ErrorToMap

Function ErrorToMap

client/errors.go:42–60  ·  view source on GitHub ↗

ErrorToMap converts an error type to a key-value map

(err error, parent string)

Source from the content-addressed store, hash-verified

40
41// ErrorToMap converts an error type to a key-value map
42func ErrorToMap(err error, parent string) map[string]interface{} {
43 data := make(map[string]interface{})
44 if parent == err.Error() {
45 // NOTE: this is done because of how errors.Wrap works, internally,
46 // to build a stacktrace. We end up with duplicate
47 // entries in the tree of errors.
48 if c, ok := err.(causer); ok {
49 return ErrorToMap(c.Cause(), parent)
50 }
51 }
52 data["message"] = err.Error()
53 if c, ok := err.(coded); ok {
54 data["code"] = c.Code()
55 }
56 if c, ok := err.(causer); ok {
57 data["cause"] = ErrorToMap(c.Cause(), data["message"].(string))
58 }
59 return data
60}
61
62// MapToError converts a JSON parsed map to an error type
63func MapToError(i map[string]interface{}) error {

Callers

nothing calls this directly

Calls 3

CauseMethod · 0.65
CodeMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected