package apperrors import "errors" type ErrorType int const ( ErrorOther ErrorType = iota ErrorNetwork ErrorGemini ) type AppError struct { Type ErrorType StatusCode int Fatal bool Err error } func (e *AppError) Error() string { if e == nil || e.Err == nil { return "" } return e.Err.Error() } func (e *AppError) Unwrap() error { if e == nil { return nil } return e.Err } func NewError(err error) error { return &AppError{ Type: ErrorOther, StatusCode: 0, Fatal: false, Err: err, } } func NewFatalError(err error) error { return &AppError{ Type: ErrorOther, StatusCode: 0, Fatal: true, Err: err, } } func NewNetworkError(err error) error { return &AppError{ Type: ErrorNetwork, StatusCode: 0, Fatal: false, Err: err, } } func NewGeminiError(err error, statusCode int) error { return &AppError{ Type: ErrorGemini, StatusCode: statusCode, Fatal: false, Err: err, } } func GetStatusCode(err error) int { var appError *AppError if errors.As(err, &appError) && appError != nil { return appError.StatusCode } return 0 } func IsGeminiError(err error) bool { var appError *AppError if errors.As(err, &appError) && appError != nil { if appError.Type == ErrorGemini { return true } } return false } func IsFatal(err error) bool { var appError *AppError if errors.As(err, &appError) && appError != nil { return appError.Fatal } return false }