refactor: 去掉 GetDerivatives 的假 error 返回 + 同步 API 文档
GetDerivatives 签名里的 error 返回永远是 nil,controller 那段 if err != nil 是死分支,会误导调用方以为存在"全失败"语义。当前产品策略是 best-effort response:局部失败 → warnings,bundle 永远非 nil,HTTP 永远 200。 等 Hermes 上游真要求"全失败 → 5xx"时再重新引入 error 返回。 同时把 docs/dev.md §13.5 示例补上 warnings 字段(上次重构遗漏的文档同步)。
This commit is contained in:
@@ -964,7 +964,8 @@ Response:
|
||||
"global": [],
|
||||
"topTraderPosition": []
|
||||
},
|
||||
"takerBuySellVolume": []
|
||||
"takerBuySellVolume": [],
|
||||
"warnings": []
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -76,10 +76,7 @@ func RegisterMarket(r fiber.Router, d MarketDeps) {
|
||||
return fiber.NewError(fiber.StatusBadRequest, "symbol is required")
|
||||
}
|
||||
|
||||
bundle, warnings, err := d.MarketQuery.GetDerivatives(c.UserContext(), symbol, period)
|
||||
if err != nil {
|
||||
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
|
||||
}
|
||||
bundle, warnings := d.MarketQuery.GetDerivatives(c.UserContext(), symbol, period)
|
||||
|
||||
return c.JSON(fiber.Map{
|
||||
"symbol": symbol,
|
||||
|
||||
@@ -36,7 +36,7 @@ func NewMarketQueryUsecase(
|
||||
}
|
||||
}
|
||||
|
||||
func (u *MarketQueryUsecase) GetDerivatives(ctx context.Context, symbol, period string) (*entity.DerivativesBundle, []string, error) {
|
||||
func (u *MarketQueryUsecase) GetDerivatives(ctx context.Context, symbol, period string) (*entity.DerivativesBundle, []string) {
|
||||
var (
|
||||
currentFund *entity.FundingRate
|
||||
currentOI *entity.OpenInterest
|
||||
@@ -109,5 +109,5 @@ func (u *MarketQueryUsecase) GetDerivatives(ctx context.Context, symbol, period
|
||||
if warnings == nil {
|
||||
warnings = []string{}
|
||||
}
|
||||
return bundle, warnings, nil
|
||||
return bundle, warnings
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user