Better error when the server is unable to write in the backend (#8697)

This commit is contained in:
Anis Elleuch
2019-12-26 07:05:54 +01:00
committed by kannappanr
parent cd59a945d8
commit c31e67dcce
3 changed files with 42 additions and 8 deletions

View File

@@ -36,6 +36,16 @@ type Err struct {
hint string
}
// Clone returns a new Err struct with the same information
func (u Err) Clone() Err {
return Err{
msg: u.msg,
detail: u.detail,
action: u.action,
hint: u.hint,
}
}
// Return the error message
func (u Err) Error() string {
if u.detail == "" {
@@ -49,12 +59,16 @@ func (u Err) Error() string {
// Msg - Replace the current error's message
func (u Err) Msg(m string, args ...interface{}) Err {
return Err{
msg: fmt.Sprintf(m, args...),
detail: u.detail,
action: u.action,
hint: u.hint,
}
e := u.Clone()
e.msg = fmt.Sprintf(m, args...)
return e
}
// Hint - Replace the current error's message
func (u Err) Hint(m string, args ...interface{}) Err {
e := u.Clone()
e.hint = fmt.Sprintf(m, args...)
return e
}
// ErrFn function wrapper