auth/internal/domain/error.go

41 lines
684 B
Go
Raw Normal View History

package domain
import (
"fmt"
"golang.org/x/xerrors"
)
2021-12-29 20:08:30 +00:00
// Error describes the data of a typical error.
//nolint: tagliatelle
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)
}
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-12-29 20:08:30 +00:00
p.Print(e.Description)
2021-09-22 21:32:40 +00:00
if e.URI != "" {
2022-01-08 10:53:58 +00:00
p.Print(" (", e.URI, ")")
2021-09-22 21:32:40 +00:00
}
2021-12-29 20:08:30 +00:00
if !p.Detail() {
return e
2021-09-22 21:32:40 +00:00
}
2021-12-29 20:08:30 +00:00
e.Frame.Format(p)
2021-09-22 21:32:40 +00:00
return nil
}