2021-09-29 20:35:39 +00:00
|
|
|
package domain
|
2021-07-21 23:04:00 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"golang.org/x/xerrors"
|
|
|
|
)
|
|
|
|
|
2021-09-23 18:33:30 +00:00
|
|
|
//nolint: tagliatelle
|
2021-07-21 23:04:00 +00:00
|
|
|
type Error struct {
|
|
|
|
Code string `json:"error"`
|
|
|
|
Description string `json:"error_description,omitempty"`
|
|
|
|
URI string `json:"error_uri,omitempty"`
|
|
|
|
Frame xerrors.Frame `json:"-"`
|
|
|
|
}
|
|
|
|
|
2021-09-22 21:32:40 +00:00
|
|
|
func (e Error) Error() string {
|
|
|
|
return fmt.Sprint(e)
|
2021-07-21 23:04:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e Error) Format(s fmt.State, r rune) {
|
|
|
|
xerrors.FormatError(e, s, r)
|
|
|
|
}
|
|
|
|
|
2021-09-22 21:32:40 +00:00
|
|
|
func (e Error) FormatError(p xerrors.Printer) error {
|
2021-09-23 18:32:40 +00:00
|
|
|
p.Printf("%s: %s", e.Code, e.Description)
|
2021-09-22 21:32:40 +00:00
|
|
|
|
|
|
|
if e.URI != "" {
|
2021-09-23 18:32:40 +00:00
|
|
|
p.Printf("%s", e.URI)
|
2021-09-22 21:32:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if p.Detail() {
|
|
|
|
e.Frame.Format(p)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2021-07-21 23:04:00 +00:00
|
|
|
}
|