This repository has been archived on 2022-11-03. You can view files and clone it, but cannot push or open issues or pull requests.
DevOpsOpenHack/apis/trips/tripsgo/errorMessage.go

25 lines
490 B
Go
Raw Normal View History

2022-11-03 20:41:13 +00:00
package tripsgo
import (
"encoding/json"
"strings"
)
// SerializeError - Serialize Error information to JSON format.
func SerializeError(e error, customMessage string) string {
var errorMessage struct {
Message string
}
if customMessage != "" {
message := []string{customMessage, e.Error()}
errorMessage.Message = strings.Join(message, ": ")
} else {
errorMessage.Message = e.Error()
}
serializedError, _ := json.Marshal(errorMessage)
return string(serializedError)
}