GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor: unify http error status code · gitLibs/server@2752303

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • internal/web
    • handler/common
      • validation.go
    • res
      • error.go
  • openapi
    • v0.yaml
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎internal/web/handler/common/validation.go‎

Copy file name to clipboardExpand all lines: internal/web/handler/common/validation.go
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,14 @@ import (
2626
"github.com/go-playground/validator/v10"
2727
zhTranslations "github.com/go-playground/validator/v10/translations/zh"
2828
"github.com/gofiber/fiber/v2"
29-
"github.com/gofiber/fiber/v2/utils"
3029

3130
"github.com/bangumi/server/internal/pkg/errgo"
3231
"github.com/bangumi/server/internal/web/res"
3332
)
3433

3534
func (h Common) ValidationError(c *fiber.Ctx, err error) error {
36-
return res.JSON(c.Status(http.StatusUnprocessableEntity), res.Error{
37-
Title: utils.StatusMessage(http.StatusUnprocessableEntity),
35+
return res.JSON(c.Status(http.StatusBadRequest), res.Error{
36+
Title: "Bad Request",
3837
Description: "can't validate request body",
3938
Details: h.translationValidationError(err),
4039
})
Collapse file

‎internal/web/res/error.go‎

Copy file name to clipboardExpand all lines: internal/web/res/error.go
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func FromError(c *fiber.Ctx, err error, code int, message string) error {
5757
}
5858

5959
func JSONError(c *fiber.Ctx, err error) error {
60-
c.Status(http.StatusUnprocessableEntity)
60+
c.Status(http.StatusBadRequest)
6161

6262
return JSON(c, Error{
6363
Title: "JSON Syntax Error",
Collapse file

‎openapi/v0.yaml‎

Copy file name to clipboardExpand all lines: openapi/v0.yaml
-16Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,6 @@ openapi: 3.0.2
22
info:
33
title: ""
44
version: ""
5-
description: |
6-
## 错误处理
7-
8-
### 不带有 Body 的请求:
9-
10-
`400`: 请求 path 或者 query 中的数据错误,如 `?subject_id=-1`,或者对应的信息缺失。
11-
12-
### 带有 Body 的请求:
13-
14-
`415`: 请求没有设置 `content-type` header,应该统一设置为 `application/json`。
15-
16-
`422`: 无法以 JSON 格式解析请求(跟 WebDAV 的 RFC 定义的不同)
17-
18-
`400`: 请求数据错误,比如请求体或者 path, query 中的数据错误。(不代表请求体一定能够正确以 JSON 格式解析)
19-
20-
**未用到的多余的字段会被直接忽略,不会报错。**
215

226
tags:
237
- name: "条目"

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.