Skip to content

Instantly share code, notes, and snippets.

@sgarcez
Last active April 24, 2018 10:49
Show Gist options
  • Save sgarcez/6f94a36aed264db6add4d851ae4a8e2e to your computer and use it in GitHub Desktop.
Save sgarcez/6f94a36aed264db6add4d851ae4a8e2e to your computer and use it in GitHub Desktop.
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