refactor(adapter): 抽出 provider 抽象层(阶段0),controller 不再依赖火山实现
- 新增 adapter/provider:Provider/Capabilities/Request/Credentials/MetricsRecorder/UpstreamError + 注册表 - 火山实现 Provider(provider.go),Synthesis 收敛为私有 synthesize,提供 BuildRequest 过渡映射 - controller 经 provider.Get(name).Synthesize 调用,voice 路由改在 Request 上覆盖 - UpstreamError 上移到 provider 包,火山用类型别名沿用旧名 - setting 新增 GetTTSRequest/GetDefaultFormat/GetDefaultProviderName - main.go 空导入注册火山 - docs/UPSTREAM_ADAPTER_GUIDE.md 更新为 v1.1(阶段0已落地)
This commit is contained in:
@@ -1,27 +1,9 @@
|
||||
package volcano
|
||||
|
||||
import "fmt"
|
||||
import "github.com/volcano-tts/tts-api/adapter/provider"
|
||||
|
||||
// UpstreamError 表示火山 v3 返回的 业务错误(code != 0 且 != 20000000)或传输错误。
|
||||
// 包含上游错误码,便于 telemetry 把它作为 label。
|
||||
type UpstreamError struct {
|
||||
Code int
|
||||
Message string
|
||||
Stage string // "request"/"stream"/"http" - 出错阶段
|
||||
Wrapped error
|
||||
}
|
||||
|
||||
func (e *UpstreamError) Error() string {
|
||||
if e.Wrapped != nil {
|
||||
return fmt.Sprintf("volcano %s: code=%d %s: %v", e.Stage, e.Code, e.Message, e.Wrapped)
|
||||
}
|
||||
return fmt.Sprintf("volcano %s: code=%d %s", e.Stage, e.Code, e.Message)
|
||||
}
|
||||
|
||||
func (e *UpstreamError) Unwrap() error { return e.Wrapped }
|
||||
|
||||
// IsAuth 当上游返回认证/权限类错误时返回 true。
|
||||
func (e *UpstreamError) IsAuth() bool {
|
||||
return e.Code == 45000000 || e.Code == 55000000 ||
|
||||
e.Code == 401 || e.Code == 403
|
||||
}
|
||||
// UpstreamError 是 provider.UpstreamError 的别名。
|
||||
//
|
||||
// 通用错误类型已上移到 provider 包,这样主干(controller)只需 import provider 即可
|
||||
// 判断上游错误,不必依赖具体适配器。火山包内部沿用旧名,构造处零改动。
|
||||
type UpstreamError = provider.UpstreamError
|
||||
|
||||
Reference in New Issue
Block a user