12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package domain
- import (
- "errors"
- "fmt"
- _ "golang.org/x/text/message"
- )
- type ErrorKind int
- const (
- NoError ErrorKind = iota
- Unimplemented
- ShortNotCreated
- ShortNotFound
- TargetBlockedError
- TargetCensoredError
- TargetInvalidError
- StorageReadError
- StorageWriteError
- StorageUnspecifiedError
- )
- var Errors = map[ErrorKind]string{
- NoError: "No error",
- Unimplemented: "Not yet implemented",
- ShortNotCreated: "Short URL not created for a new target",
- ShortNotFound: "Short URL not defined",
- TargetBlockedError: "Target blocked",
- TargetCensoredError: "Target unavailable for legal reasons",
- TargetInvalidError: "Target invalid",
- StorageReadError: "Storage read error",
- StorageWriteError: "Storage write error",
- StorageUnspecifiedError: "Storage unspecified error",
- }
- type Error struct {
- error
- Kind ErrorKind
- }
- func MakeError(kind ErrorKind, detail string) Error {
- var message string
- if len(detail) == 0 {
- message = Errors[kind]
- } else {
- message = fmt.Sprintf("%s: %s", Errors[kind], detail)
- }
- return Error{
- Kind: kind,
- error: errors.New(message),
- }
- }
|