✨ Add SettableError
This commit is contained in:
parent
95c9d7282b
commit
c0dc44e28e
3 changed files with 88 additions and 5 deletions
12
interface.go
12
interface.go
|
|
@ -6,12 +6,24 @@ package errors
|
|||
// GetStatus should return an appropriate HTTP status.
|
||||
// GetMsg should return a message suitable to display to the end user. If the message
|
||||
// returned by Error is safe for the end user, it may simply call that.
|
||||
// GetStatus should not return a value outside of the 100 - 599 range.
|
||||
type ResponsableError interface {
|
||||
Error() string
|
||||
GetStatus() int
|
||||
GetMsg() string
|
||||
}
|
||||
|
||||
// SettableError is a ResponsableError which can be modified after initial creation.
|
||||
// The Status method can set the status, while the Msg method can set user message.
|
||||
// If any values are passed after the message, it should be passed to fmt.Sprintf for formatting.
|
||||
// Methods are chainable.
|
||||
// SetStatus should not use a value outside of 100-599. It may either ignore such values, or panic.
|
||||
type SettableError interface {
|
||||
ResponsableError
|
||||
Status(int) SettableError
|
||||
Msg(string, ...any) SettableError
|
||||
}
|
||||
|
||||
// UnwrappableError allows a ResponsableError to wrap another error.
|
||||
// It may be appropriate for Error() to delegate to the wrapped error.
|
||||
type UnwrappableError interface {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue