s3browser-backend/internal/errors/errors.go

30 lines
540 B
Go
Raw Normal View History

2021-09-24 13:39:23 +00:00
package s3browser
import "fmt"
2021-09-24 13:49:51 +00:00
var (
ErrNotAuthenticated = ExtendError("UNAUTHENTICATED", "No valid authentication provided")
)
2021-09-24 13:39:23 +00:00
type ExtendedError struct {
Message string
Code string
}
func (err *ExtendedError) Error() string {
return err.Message
}
func (err *ExtendedError) Extensions() map[string]interface{} {
return map[string]interface{}{
"code": err.Code,
}
}
func ExtendError(code, format string, a ...interface{}) *ExtendedError {
return &ExtendedError{
Message: fmt.Sprintf(format, a...),
Code: code,
}
}