🐛 fix(handlers): 统一错误响应为安全 JSON 并补参数校验
- 新增 respondError:JSON 安全编码,客户端错误返回 400,服务端错误返回 500 - 收编 book/content/media/category 中 13 处 fmt.Fprintf 内联 JSON,修复错误信息含引号/换行时产出非法 JSON 的问题 - search/detail/catalog/multi-detail/content/multi-content/item-summary/audio/video 补必需参数校验,缺参返回 400 - search 的 offset/tab_type 非数字时返回 400,不再静默置 0 - 补齐 multi-detail/multi-content 的请求统计计数 - 新增 error_response_test.go:3 个测试锁定错误响应行为 - openapi.yaml 新增 ServerError 响应组件,15 个业务接口补 400/500 响应定义 BREAKING CHANGE: 业务接口错误不再返回 HTTP 200,缺参返回 400,上游失败返回 500
This commit is contained in:
1 parent
1eccebedf9
commit
d1774a3902
7 files changed
+209
-52
No files matched your search
@@ -169,6 +169,10 @@ paths:
|
||||
$ref: "#/components/schemas/UpstreamResponse"
|
||||
example: { code: 0, msg: success, data: { search_book_data_list: [], has_more: 1 } }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/detail:
|
||||
get:
|
||||
tags: [书籍]
|
||||
@@ -183,6 +187,10 @@ paths:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/UpstreamResponse" }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/info:
|
||||
get:
|
||||
tags: [书籍]
|
||||
@@ -197,6 +205,10 @@ paths:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/UpstreamResponse" }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/catalog:
|
||||
get:
|
||||
tags: [书籍]
|
||||
@@ -211,6 +223,10 @@ paths:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/UpstreamResponse" }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/directory/all_items:
|
||||
get:
|
||||
tags: [书籍]
|
||||
@@ -225,6 +241,10 @@ paths:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/UpstreamResponse" }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/multi-detail:
|
||||
get:
|
||||
tags: [书籍]
|
||||
@@ -244,6 +264,10 @@ paths:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/UpstreamResponse" }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/content:
|
||||
get:
|
||||
tags: [内容]
|
||||
@@ -295,6 +319,10 @@ paths:
|
||||
properties:
|
||||
book_id: { type: string, description: 所属书籍 ID }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/multi-content:
|
||||
get:
|
||||
tags: [内容]
|
||||
@@ -327,6 +355,10 @@ paths:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/UpstreamResponse" }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/item-summary:
|
||||
get:
|
||||
tags: [内容]
|
||||
@@ -346,6 +378,10 @@ paths:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/UpstreamResponse" }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/chapter_review:
|
||||
get:
|
||||
tags: [评论]
|
||||
@@ -371,6 +407,8 @@ paths:
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/review:
|
||||
get:
|
||||
tags: [评论]
|
||||
@@ -405,6 +443,8 @@ paths:
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/review_html:
|
||||
get:
|
||||
tags: [评论]
|
||||
@@ -432,6 +472,8 @@ paths:
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/audio:
|
||||
get:
|
||||
tags: [多媒体]
|
||||
@@ -459,6 +501,10 @@ paths:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/UpstreamResponse" }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/audio/proxy/{key}:
|
||||
get:
|
||||
tags: [多媒体]
|
||||
@@ -507,6 +553,10 @@ paths:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/UpstreamResponse" }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/manga:
|
||||
get:
|
||||
tags: [多媒体]
|
||||
@@ -547,6 +597,8 @@ paths:
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/manga/image/{item_id}/{index}:
|
||||
get:
|
||||
tags: [多媒体]
|
||||
@@ -606,6 +658,10 @@ paths:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/UpstreamResponse" }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/category-landing:
|
||||
get:
|
||||
tags: [分类]
|
||||
@@ -633,6 +689,10 @@ paths:
|
||||
application/json:
|
||||
schema: { $ref: "#/components/schemas/UpstreamResponse" }
|
||||
|
||||
"400":
|
||||
$ref: "#/components/responses/BadRequest"
|
||||
"500":
|
||||
$ref: "#/components/responses/ServerError"
|
||||
/emoji/{file}:
|
||||
get:
|
||||
tags: [静态资源]
|
||||
@@ -660,6 +720,7 @@ paths:
|
||||
text/plain:
|
||||
schema: { type: string }
|
||||
|
||||
|
||||
components:
|
||||
securitySchemes:
|
||||
accessKeyQuery:
|
||||
@@ -695,6 +756,13 @@ components:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ErrorResponse"
|
||||
example: { code: -1, msg: "访问被拒绝:无效的访问密钥" }
|
||||
ServerError:
|
||||
description: 服务端错误(上游请求失败等)
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: "#/components/schemas/ErrorResponse"
|
||||
example: { code: -1, msg: "获取内容失败: 请求超时" }
|
||||
BadRequest:
|
||||
description: 参数缺失或格式错误
|
||||
content:
|
||||
|
||||
Reference in new issue
Block a user