1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package domain
- import (
- "errors"
- "fmt"
- )
- 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),
- }
- }
|