package terror const ( errCodeUnauthorized = 100 errCodeTokenExpired = 101 errCodeNoAccessToken = 102 ) // Common // IError : parent error. type IError struct { code int `default:"999"` message string description string } func (err IError) Error() string { return err.message } // IsSameError : Compare internal error code if target could convert IError instance. func (err IError) IsSameError(target error) bool { if convertError, e := target.(IError); !e { return false } else { return convertError.code == err.code } } // SetDescriptor : Could be add access token description. func (err IError) SetDescriptor(desc string) IError { err.description = desc return err } // // ErrorUnAuthorized : Error when request with unauthrized token type ErrorUnAuthorized IError // NewErrorUnAuthorized : Make a error instance func NewErrorUnAuthorized() ErrorUnAuthorized { return ErrorUnAuthorized{ code: errCodeUnauthorized, message: "Unauthorized!", } } // ErrorTokenExpired : Token is expired! type ErrorTokenExpired IError // NewErrorTokenExpired : Make a error instance notifing Token Expired! func NewErrorTokenExpired() IError { return IError{ code: errCodeUnauthorized, message: "Expired token!", } } // ErrorNoAccessToken : No access token. But it maybe unregistered user. type ErrorNoAccessToken IError // NewErrorNoAccessToken : make a instance for NoAccessToken error. func NewErrorNoAccessToken() IError { return IError{ code: errCodeNoAccessToken, message: "Invalid access token.", } }