Files
huya-go/internal/huya/diagnose.go
T

30 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package huya
import (
"errors"
"fmt"
"huya-go/internal/wup"
)
// ErrProtocolResponse 表示服务端响应的结构与协议约定不符(典型是缺少 tRsp/tResp)。
//
// 这类错误既不是网络错误也不是业务失败:它说明服务端回了一个解不出来的包
// (风控拦截、错误信封、被截断的帧都可能)。单独标记出来是为了让上层能把它
// 与普通失败分开统计(见 sniper.CategoryProtocol),并在报错里带上 WUP 诊断信息。
var ErrProtocolResponse = errors.New("协议响应异常")
// rawFrameHeadBytes 是 debug 日志里打印的原始帧前缀长度。
const rawFrameHeadBytes = 32
// protocolResponseError 组装「缺少 tRsp/tResp」错误,并带上 WUP 响应诊断。
//
// 过去这里只有一句文案,服务端返回的 iRet/status/context 全被丢掉,
// 事后只能重放抓包(2026-10-16 pc-3 同一账号连续 13 次命中,无法定性)。
func protocolResponseError(service, method string, resp *wup.Response) error {
if resp == nil {
return fmt.Errorf("%w: %s.%s 响应缺少 tRsp/tResp", ErrProtocolResponse, service, method)
}
return fmt.Errorf("%w: %s.%s 响应缺少 tRsp/tResp(%s)", ErrProtocolResponse, service, method, resp.Diagnose())
}