滑动续期、网络错误归类、API Key 激活乐观锁与生效提示
This commit is contained in:
@@ -283,11 +283,28 @@ func respondError(c *gin.Context, err error) {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
// 代理/网络类连接失败以 502 透出明确文案,不落无信息量的 500
|
||||
if msg, ok := oci.UpstreamNetworkError(err); ok {
|
||||
respondNetworkError(c, msg)
|
||||
return
|
||||
}
|
||||
id := newRequestID()
|
||||
log.Printf("[ERR %s] %s %s: %v", id, c.Request.Method, requestPath(c), err)
|
||||
c.JSON(http.StatusInternalServerError, gin.H{"error": "服务器内部错误", "requestId": id})
|
||||
}
|
||||
|
||||
// respondNetworkError 以 502 透出上游连接失败;服务端留日志,requestId 供关联。
|
||||
func respondNetworkError(c *gin.Context, msg string) {
|
||||
id := newRequestID()
|
||||
log.Printf("[NET %s] %s %s: %s", id, c.Request.Method, requestPath(c), msg)
|
||||
c.JSON(http.StatusBadGateway, gin.H{
|
||||
"error": msg,
|
||||
"hint": "上游连接失败(代理或网络),请检查该租户关联代理的可用性",
|
||||
"code": "UpstreamNetwork",
|
||||
"requestId": id,
|
||||
})
|
||||
}
|
||||
|
||||
// newRequestID 生成错误关联 ID(8 字节随机 hex),响应与服务端日志据此对应。
|
||||
func newRequestID() string {
|
||||
b := make([]byte, 8)
|
||||
|
||||
Reference in New Issue
Block a user