errors

package
v0.0.0-...-dfd90ba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Common delivery
	ErrMissingFile = errors.New("missing file")

	// Common repository
	ErrDb           = errors.New("db error")
	ErrImageService = errors.New("image service error")

	// Profile
	ErrTooShortUsername = errors.New("username must be at least 4 characters")
	ErrTooLongUsername  = errors.New("username must be no more than 30 characters")
	ErrEmptyName        = errors.New("name must not be empty")
	ErrTooLongName      = errors.New("name must be no more than 60 characters")

	// Not found
	ErrUserNotFound         = errors.New("user not found")
	ErrProfileNotFound      = errors.New("profile not found")
	ErrBoardNotFound        = errors.New("board not found")
	ErrPinNotFound          = errors.New("pin not found")
	ErrLikeNotFound         = errors.New("no such like")
	ErrFollowingNotFound    = errors.New("no such following")
	ErrChatNotFound         = errors.New("chat not found")
	ErrLinkNotFound         = errors.New("link not found")
	ErrNotificationNotFound = errors.New("notification not found")

	// CSRF
	ErrBadCsrfTokenCookie = errors.New("bad csrf token cookie")
	ErrBadTokenTime       = errors.New("bad token time")
	ErrBadTokenData       = errors.New("bad token data")

	// Auth
	ErrWrongLoginOrPassword = errors.New("wrong login or password")
	ErrUserAlreadyExists    = errors.New("user already exists")

	// Invalid Param
	ErrInvalidUserIdParam  = errors.New("invalid user id param")
	ErrInvalidBoardIdParam = errors.New("invalid board id param")
	ErrInvalidPinIdParam   = errors.New("invalid pin id param")
	ErrInvalidPageParam    = errors.New("invalid page param")
	ErrInvalidLimitParam   = errors.New("invalid limit param")
	ErrInvalidLikedParam   = errors.New("invalid liked param")
	ErrInvalidChatIDParam  = errors.New("invalid chat id param")
	ErrInvalidLinkIDParam  = errors.New("invalid link param")

	// WebSocket
	ErrUpgradeToWebSocket = errors.New("failed to upgrade protocol to websocket")

	ErrBadParams              = errors.New("bad params")
	ErrBadRequest             = errors.New("bad request")
	ErrBadSessionCookie       = errors.New("bad session cookie")
	ErrFileCopy               = errors.New("file copy error")
	ErrParseForm              = errors.New("parse form error")
	ErrParseJson              = errors.New("parse json error")
	ErrReadBody               = errors.New("read request body error")
	ErrSameUserId             = errors.New("same user id")
	ErrService                = errors.New("service error")
	ErrCreateResponse         = errors.New("create response error")
	ErrCreateCsrfToken        = errors.New("create csrf token error")
	ErrUnauthorized           = errors.New("unauthorized")
	ErrNoContent              = errors.New("no content")
	ErrForbidden              = errors.New("access denied")
	ErrTokenExpired           = errors.New("token expired")
	ErrLikeAlreadyExists      = errors.New("like already exists")
	ErrFollowingAlreadyExists = errors.New("following already exists")
	ErrPinAlreadyAdded        = errors.New("pin already added")
	ErrChatAlreadyExists      = errors.New("chat already exists")

	// Boards
	ErrTooLongBoardName        = errors.New("board name must be no more than 256 characters")
	ErrTooLongBoardDescription = errors.New("board description must be no more than 500 characters")
	ErrInvalidPrivacy          = errors.New("invalid privacy")

	// Pins
	ErrTooLongPinTitle       = errors.New("pin title must be no more than 100 characters")
	ErrTooLongPinDescription = errors.New("pin description must be no more than 500 characters")
)
View Source
var ErrorsByNames = map[string]error{

	ErrMissingFile.Error(): ErrMissingFile,

	ErrDb.Error():           ErrDb,
	ErrImageService.Error(): ErrImageService,

	ErrTooShortUsername.Error(): ErrTooShortUsername,
	ErrTooLongUsername.Error():  ErrTooLongUsername,
	ErrEmptyName.Error():        ErrEmptyName,
	ErrTooLongName.Error():      ErrTooLongName,

	ErrUserNotFound.Error():      ErrUserNotFound,
	ErrProfileNotFound.Error():   ErrProfileNotFound,
	ErrBoardNotFound.Error():     ErrBoardNotFound,
	ErrPinNotFound.Error():       ErrPinNotFound,
	ErrLikeNotFound.Error():      ErrLikeNotFound,
	ErrFollowingNotFound.Error(): ErrFollowingNotFound,
	ErrChatNotFound.Error():      ErrChatNotFound,
	ErrLinkNotFound.Error():      ErrLinkNotFound,

	ErrBadCsrfTokenCookie.Error(): ErrBadCsrfTokenCookie,
	ErrBadTokenTime.Error():       ErrBadTokenTime,
	ErrBadTokenData.Error():       ErrBadTokenData,

	ErrWrongLoginOrPassword.Error(): ErrWrongLoginOrPassword,
	ErrUserAlreadyExists.Error():    ErrUserAlreadyExists,

	ErrInvalidUserIdParam.Error():  ErrInvalidUserIdParam,
	ErrInvalidBoardIdParam.Error(): ErrInvalidBoardIdParam,
	ErrInvalidPinIdParam.Error():   ErrInvalidPinIdParam,
	ErrInvalidPageParam.Error():    ErrInvalidPageParam,
	ErrInvalidLimitParam.Error():   ErrInvalidLimitParam,
	ErrInvalidPrivacy.Error():      ErrInvalidPrivacy,
	ErrInvalidChatIDParam.Error():  ErrInvalidChatIDParam,
	ErrInvalidLinkIDParam.Error():  ErrInvalidLinkIDParam,

	ErrUpgradeToWebSocket.Error(): ErrUpgradeToWebSocket,

	ErrBadParams.Error():              ErrBadParams,
	ErrBadRequest.Error():             ErrBadRequest,
	ErrBadSessionCookie.Error():       ErrBadSessionCookie,
	ErrFileCopy.Error():               ErrFileCopy,
	ErrParseForm.Error():              ErrParseForm,
	ErrParseJson.Error():              ErrParseJson,
	ErrSameUserId.Error():             ErrSameUserId,
	ErrService.Error():                ErrService,
	ErrCreateResponse.Error():         ErrCreateResponse,
	ErrCreateCsrfToken.Error():        ErrCreateCsrfToken,
	ErrUnauthorized.Error():           ErrUnauthorized,
	ErrNoContent.Error():              ErrNoContent,
	ErrForbidden.Error():              ErrForbidden,
	ErrTokenExpired.Error():           ErrTokenExpired,
	ErrLikeAlreadyExists.Error():      ErrLikeAlreadyExists,
	ErrFollowingAlreadyExists.Error(): ErrFollowingAlreadyExists,
	ErrPinAlreadyAdded.Error():        ErrPinAlreadyAdded,
	ErrChatAlreadyExists.Error():      ErrChatAlreadyExists,
}

Functions

func GRPCUnwrapper

func GRPCUnwrapper(err error) error

func GRPCWrapper

func GRPCWrapper(err error) error

func GetGRPCCodeByError

func GetGRPCCodeByError(err error) (codes.Code, bool)

func GetHTTPCodeByError

func GetHTTPCodeByError(err error) (int, bool)

func RestoreHTTPError

func RestoreHTTPError(err error) error

Types

type ErrRepositoryQuery

type ErrRepositoryQuery struct {
	Func   string // the failing function name
	Query  string // query
	Params []any  // query params
	Err    error  // original error
}

func (ErrRepositoryQuery) Error

func (e ErrRepositoryQuery) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL