All checks were successful
Build / build (push) Successful in 2m17s
Extract business logic from gRPC handlers into a dedicated service package. Add context support throughout for cancellation and timeouts. Move models to their own package, remove hardcoded credentials from config, and simplify parsers to only handle HTML parsing.
35 lines
590 B
Go
35 lines
590 B
Go
package errors
|
||
|
||
import (
|
||
"errors"
|
||
"fmt"
|
||
)
|
||
|
||
var ErrLoginFailed = errors.New("login failed")
|
||
|
||
// AppError 携带操作名(Op)与中文提示(Msg)的错误类型,用于统一日志与错误上报。
|
||
type AppError struct {
|
||
Op string
|
||
Err error
|
||
Msg string
|
||
}
|
||
|
||
func (e *AppError) Error() string {
|
||
if e.Msg != "" {
|
||
return fmt.Sprintf("%s: %s: %v", e.Op, e.Msg, e.Err)
|
||
}
|
||
return fmt.Sprintf("%s: %v", e.Op, e.Err)
|
||
}
|
||
|
||
func (e *AppError) Unwrap() error {
|
||
return e.Err
|
||
}
|
||
|
||
func New(op string, err error, msg string) error {
|
||
return &AppError{
|
||
Op: op,
|
||
Err: err,
|
||
Msg: msg,
|
||
}
|
||
}
|