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

Function MapToError

client/errors.go:63–82  ·  view source on GitHub ↗

MapToError converts a JSON parsed map to an error type

(i map[string]interface{})

Source from the content-addressed store, hash-verified

61
62// MapToError converts a JSON parsed map to an error type
63func MapToError(i map[string]interface{}) error {
64 msg, _ := i["message"].(string)
65 code, codeOK := i["code"].(int)
66 cause, causeOK := i["cause"].(map[string]interface{})
67
68 err := errors.New(msg)
69
70 if codeOK {
71 err = &codedError{err, code}
72 }
73
74 if causeOK {
75 causeError := MapToError(cause)
76 l := len(msg) - len(causeError.Error())
77 msg = msg[:l-2]
78 err = &wrappedError{msg, causeError}
79 }
80
81 return err
82}

Callers

nothing calls this directly

Calls 2

NewMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected