/
error.go
42 lines (36 loc) · 934 Bytes
/
error.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
39
40
41
42
package bmc
import (
"encoding/json"
"regexp"
"strings"
)
type RedfishError struct {
Code string
Error struct {
MessageExtendedInfo []struct {
Message string
MessageArgs []string //?
MessageArgsCount int `json:"MessageArgs.@odata.count"`
MessageId string
RelatedProperties []string //?
RelatedPropertiesCount int `json:"RelatedProperties.@odata.count"`
Resolution string
Severity string
} `json:"@Message.ExtendedInfo"`
Code string `json:"code"`
Message string `json:"message"`
} `json:"error"`
}
func ParseRedfishError(err error) RedfishError {
var e RedfishError
if err == nil {
return e
}
reg := regexp.MustCompile(`^[0-9]{3}`)
e.Code = reg.FindString(err.Error())
if e.Code != "" {
test, _ := strings.CutPrefix(err.Error(), e.Code+":")
json.Unmarshal([]byte(test), &e)
}
return e
}