mirror of
https://github.com/1f349/lavender.git
synced 2025-02-23 14:15:08 +00:00
38 lines
648 B
Go
38 lines
648 B
Go
package auth
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
type UserSafeError struct {
|
|
Display string
|
|
Code int
|
|
Internal error
|
|
}
|
|
|
|
func (e UserSafeError) Error() string {
|
|
return fmt.Sprintf("%s [%d]: %v", e.Display, e.Code, e.Internal)
|
|
}
|
|
|
|
func (e UserSafeError) Unwrap() error {
|
|
return e.Internal
|
|
}
|
|
|
|
func BasicUserSafeError(code int, message string) UserSafeError {
|
|
return UserSafeError{
|
|
Code: code,
|
|
Display: message,
|
|
Internal: errors.New(message),
|
|
}
|
|
}
|
|
|
|
func AdminSafeError(inner error) UserSafeError {
|
|
return UserSafeError{
|
|
Code: http.StatusInternalServerError,
|
|
Display: "Internal server error",
|
|
Internal: inner,
|
|
}
|
|
}
|