-
Notifications
You must be signed in to change notification settings - Fork 285
/
errors.go
38 lines (34 loc) · 872 Bytes
/
errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package gocloak
import (
"strings"
)
// HTTPErrorResponse is a model of an error response
type HTTPErrorResponse struct {
Error string `json:"error,omitempty"`
Message string `json:"errorMessage,omitempty"`
Description string `json:"error_description,omitempty"`
}
// String returns a string representation of an error
func (e HTTPErrorResponse) String() string {
var res strings.Builder
if len(e.Error) > 0 {
res.WriteString(e.Error)
}
if len(e.Message) > 0 {
if res.Len() > 0 {
res.WriteString(": ")
}
res.WriteString(e.Message)
}
if len(e.Description) > 0 {
if res.Len() > 0 {
res.WriteString(": ")
}
res.WriteString(e.Description)
}
return res.String()
}
// NotEmpty validates that error is not emptyp
func (e HTTPErrorResponse) NotEmpty() bool {
return len(e.Error) > 0 || len(e.Message) > 0 || len(e.Description) > 0
}