common

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRequestDataInvalid     = func(s string) *customError { return CustomError("ErrRequestDataInvalid", s) }
	ErrNoPermission           = CustomError("ErrNoPermission", "you don't have permission to access")
	ErrUsernamePasswordBlank  = CustomError("ErrUsernamePasswordBlank", "username and password cannot be blank")
	ErrAccessTokenInvalid     = CustomError("ErrAccessTokenInvalid", "invalid access token")
	ErrAccessTokenInactivated = CustomError("ErrAccessTokenInactivated", "access token is disabled")
	ErrUserNotFound           = CustomError("ErrUserNotFound", "user not found or deactivated")
	ErrNoPermissionOnChatRoom = CustomError("ErrNoPermissionOnChatRoom", "you don't have permission on this chat room")
	ErrCreateRoomWithYourself = CustomError("ErrCreateRoomWithYourself", "you cannot create room has yourself")
	ErrCreateEmptyRoom        = CustomError("ErrCreateEmptyRoom", "you cannot create an empty room")
	ErrCannotCreateRoom       = CustomError("ErrCannotCreateRoom", "cannot create room")
	ErrRoomNotFound           = CustomError("ErrRoomNotFound", "room not found")
	ErrFbTokenEmpty           = CustomError("ErrFbTokenEmpty", "facebook token cannot be empty")
	ErrAKTokenEmpty           = CustomError("ErrFbTokenEmpty", "AccountKit token cannot be empty")
	ErrAppleTokenEmpty        = CustomError("ErrAppleTokenEmpty", "apple token cannot be empty")
	ErrCannotUpdateData       = CustomError("ErrCannotUpdateData", "cannot update data")
	ErrCannotLoginWithFB      = CustomError("ErrCannotLoginWithFB", "cannot login with Facebook")
	ErrCannotLoginWithApple   = CustomError("ErrCannotLoginWithApple", "cannot login with Apple")
	ErrCannotCreateUser       = CustomError("ErrCannotCreateUser", "cannot create new user")
	ErrCannotUploadImage      = CustomError("ErrCannotUploadImage", "cannot upload image")
	ErrImageIsRequired        = CustomError("ErrImageIsRequired", "image file is required")
	ErrFileIsNotImage         = CustomError("ErrFileIsNotImage", "file is not image")
	ErrImageFileTooBig        = CustomError("ErrImageFileTooBig", "image file is too big, limit 1MB")
	ErrCannotDoYourself       = CustomError("ErrCannotDoYourself", "cannot action on yourself")
	ErrCannotLikeUser         = CustomError("ErrCannotLikeUser", "cannot like user")
	ErrActionTwice            = CustomError("ErrActionTwice", "you have done before")
	ErrCannotDislikeUser      = CustomError("ErrCannotDislikeUser", "cannot dislike user")
	ErrTopicNotFound          = CustomError("ErrTopicNotFound", "topic not found")
	ErrCannotCreateUserTopic  = CustomError("ErrCannotCreateUserTopic", "cannot create user topic")
	ErrUserNameMinMaxLength   = CustomError("ErrUserNameMinMaxLength", "UserName must have length greater than 3 and less than 100")
	ErrPasswordMinMaxLength   = CustomError("ErrPasswordMinMaxLength", "Password must have length greater than 6 and less than 50")
	// Handler Error UserDeviceToken
	ErrCreateUserDeviceToken  = CustomError("ErrCreateUserDeviceToken", "cannot create user device token")
	ErrDeleteUserDeviceToken  = CustomError("ErrDeleteUserDeviceToken", "cannot delete user device token")
	ErrTokenLength            = CustomError("ErrTokenLength", "token cannot empty")
	ErrInvalidUserDeviceToken = CustomError("ErrInvalidUserDeviceToken", "user device token invalid")
	ErrCannotProcessImage     = CustomError("ErrCannotProcessImage", "cannot process image")
)
View Source
var (
	ErrCannotFetchData = func(err error) AppError {
		return NewAppErr(err, http.StatusBadRequest, "can not fetch data").WithCode("cannot_fetch_data")
	}
	ErrDB = func(err error) AppError {
		return NewAppErr(err, http.StatusBadRequest, "db error").WithCode("db_error")
	}
	ErrInvalidRequest = func(err error) AppError {
		return NewAppErr(err, http.StatusBadRequest, "invalid request").WithCode("invalid_request")
	}
	ErrInvalidRequestWithMessage = func(err error, message string) AppError {
		return NewAppErr(err, http.StatusBadRequest, message).WithCode("invalid_request")
	}
	ErrWithMessage = func(root error, err ErrorWithKey) AppError {
		if root == nil {
			return NewAppErr(errors.New(err.Error()), http.StatusBadRequest, err.Error()).WithCode(err.Key())
		}
		return NewAppErr(root, http.StatusBadRequest, err.Error()).WithCode(err.Key())
	}
	ErrCustom = func(root error, err ErrorWithKey) AppError {
		if root == nil {
			return NewAppErr(errors.New(err.Error()), http.StatusBadRequest, err.Error()).WithCode(err.Key())
		}
		return NewAppErr(root, http.StatusBadRequest, err.Error()).WithCode(err.Key())
	}
	ErrUnauthorized = func(root error, err ErrorWithKey) AppError {
		if root == nil {
			return NewAppErr(errors.New(err.Error()), http.StatusUnauthorized, err.Error()).WithCode(err.Key())
		}
		return NewAppErr(root, http.StatusUnauthorized, err.Error()).WithCode(err.Key())
	}
)
View Source
var (
	SimpleSuccessResponse = func(data interface{}) Response { return newResponse(http.StatusOK, data, nil, nil) }
	ResponseWithPaging    = func(data, param interface{}, other interface{}) Response {
		return newResponse(http.StatusOK, data, param, other)
	}
)

Response helpers

View Source
var (
	// ErrDataNotFound - data not found sometime is not an error
	// but we need this type to decouple from db (errNotFound mongodb and gorm)
	ErrDataNotFound = errors.New("data not found")
)

Functions

func CurrentAccount

func CurrentAccount(t OAuth, u Account) *currentAccount

func CustomError

func CustomError(k, v string) *customError

Types

type Account

type Account interface {
	AccountID() primitive.ObjectID
}

type AppError

type AppError struct {
	// We don't show root cause to the clients
	RootCause  error  `json:"-"`
	Code       string `json:"code"`
	Log        string `json:"log"`
	StatusCode int    `json:"status_code"`
	Message    string `json:"message"`
}

func NewAppErr

func NewAppErr(err error, statusCode int, msg string) AppError

func (AppError) Error

func (ae AppError) Error() string

AppError is error

func (AppError) RootError

func (ae AppError) RootError() error

func (AppError) WithCode

func (ae AppError) WithCode(code string) AppError

type ErrorWithKey

type ErrorWithKey interface {
	error
	Key() string
}

type OAuth

type OAuth interface {
	OAuthID() string
}

type OrderBy

type OrderBy struct {
	Key    string
	IsDesc bool
}

type Paging

type Paging struct {
	Limit int `json:"limit" form:"limit"`
	Total int `json:"total" form:"total"`
	Page  int `json:"page" form:"page"`
}

func (*Paging) FullFill

func (p *Paging) FullFill()

type Requester

type Requester interface {
	OAuth
	Account
}

type Response

type Response struct {
	Code   int         `json:"code"`
	Data   interface{} `json:"data"`
	Param  interface{} `json:"param,omitempty"`
	Paging interface{} `json:"paging,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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