Always make fatal errors json-serializable (#14396)
This commit is contained in:
parent
a8f95ef6d0
commit
4d6109d3ab
3 changed files with 39 additions and 16 deletions
21
cmd/error.go
21
cmd/error.go
|
|
@ -28,6 +28,27 @@ const (
|
|||
ClassSponsorship
|
||||
)
|
||||
|
||||
// FatalError is an error that can be marshaled
|
||||
type FatalError struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (e *FatalError) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
func (e FatalError) MarshalJSON() ([]byte, error) {
|
||||
if je, ok := e.err.(json.Marshaler); ok {
|
||||
return je.MarshalJSON()
|
||||
}
|
||||
|
||||
return json.Marshal(struct {
|
||||
Error string `json:"error"`
|
||||
}{
|
||||
Error: e.err.Error(),
|
||||
})
|
||||
}
|
||||
|
||||
// DeviceError indicates the specific device that failed
|
||||
type DeviceError struct {
|
||||
Name string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue