Files
doc_ai_backed/pkg/common/errors.go
yoge a29936f31c feat: add email verification code for registration and optimize email service
- Add POST /user/email/code endpoint to send 6-digit verification code
- Require email code verification before completing registration
- Add email code cache with 10min TTL and 5/day send rate limit
- Fix nil client guard, TLS conn leak, domain parsing, and Resend error body in email pkg
- Deploy via ssh inline command using current branch

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-27 01:47:06 +08:00

71 lines
2.0 KiB
Go

package common
type ErrorCode int
const (
CodeSuccess = 200
CodeParamError = 400
CodeUnauthorized = 401
CodeTokenExpired = 4011
CodeForbidden = 403
CodeNotFound = 404
CodeInvalidStatus = 405
CodeDBError = 500
CodeSystemError = 501
CodeTaskNotComplete = 1001
CodeRecordRepeat = 1002
CodeSmsCodeError = 1003
CodeEmailExists = 1004
CodeEmailNotFound = 1005
CodePasswordMismatch = 1006
CodeEmailCodeError = 1007
CodeEmailSendLimit = 1008
)
const (
CodeSuccessMsg = "success"
CodeParamErrorMsg = "param error"
CodeUnauthorizedMsg = "unauthorized"
CodeTokenExpiredMsg = "token expired"
CodeForbiddenMsg = "forbidden"
CodeNotFoundMsg = "not found"
CodeInvalidStatusMsg = "invalid status"
CodeDBErrorMsg = "database error"
CodeSystemErrorMsg = "system error"
CodeTaskNotCompleteMsg = "task not complete"
CodeRecordRepeatMsg = "record repeat"
CodeSmsCodeErrorMsg = "sms code error"
CodeEmailExistsMsg = "email already registered"
CodeEmailNotFoundMsg = "email not found"
CodePasswordMismatchMsg = "password mismatch"
CodeEmailCodeErrorMsg = "email code error"
CodeEmailSendLimitMsg = "email send limit reached"
)
type BusinessError struct {
Code ErrorCode
Message string
Err error
}
func (e *BusinessError) Error() string {
return e.Message
}
func NewError(code ErrorCode, message string, err error) *BusinessError {
return &BusinessError{
Code: code,
Message: message,
Err: err,
}
}
// 预定义业务错误
var (
ErrEmailExists = NewError(CodeEmailExists, CodeEmailExistsMsg, nil)
ErrEmailNotFound = NewError(CodeEmailNotFound, CodeEmailNotFoundMsg, nil)
ErrPasswordMismatch = NewError(CodePasswordMismatch, CodePasswordMismatchMsg, nil)
ErrEmailCodeError = NewError(CodeEmailCodeError, CodeEmailCodeErrorMsg, nil)
ErrEmailSendLimit = NewError(CodeEmailSendLimit, CodeEmailSendLimitMsg, nil)
)