Last active
April 24, 2018 10:49
-
-
Save sgarcez/6f94a36aed264db6add4d851ae4a8e2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type lambdaError struct { | |
code string | |
message string | |
origErr error | |
} | |
func (e lambdaError) Error() string { | |
b, err := json.Marshal(e) | |
if err != nil { | |
log.Println("cannot marshal Error:", e) | |
panic(err) | |
} | |
return string(b[:]) | |
} | |
func (e lambdaError) MarshalJSON() ([]byte, error) { | |
return json.Marshal(&struct { | |
Code string `json:"code"` | |
PublicMessage string `json:"public_message"` | |
PrivateMessage string `json:"private_message"` | |
}{ | |
Code: e.code, | |
PublicMessage: e.message, | |
PrivateMessage: e.origErr.Error(), | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment