feat: add project-owned error catalogs and HTTP 200 failure contracts

This commit is contained in:
2026-09-24 12:40:05 +08:00
parent bb2caefbb4
commit ebfd279f9a
42 changed files with 1897 additions and 120 deletions

View File

@@ -0,0 +1,36 @@
syntax = "v1"
errorCatalog CommonErrors (
defaultStatus: 200
errors: {
"UsernameInvalid": {"key": "USERNAME_INVALID", "code": 400002, "message": "用户名格式不正确"},
"PasswordInvalid": {"key": "PASSWORD_INVALID", "code": 400002, "message": "密码格式不正确"},
"PermissionDenied": {"key": "PERMISSION_DENIED", "status": 403, "code": 403001, "message": "没有权限"}
}
)
response CommonResponse (
codeType: int32
successCode: 0
errorCode: 9999
body: {"ok": "${ok}", "code": "${code}", "data": "${data}"}
errorBody: {"ok": "${ok}", "code": "${code}", "msg": "${message}"}
)
type TokenResponse {
Token string `json:"token"`
}
@server (
group: account
response: CommonResponse
errors: UsernameInvalid, PasswordInvalid, PermissionDenied
)
service errors-api {
@handler token
post /token returns (TokenResponse)
@response raw
@handler raw
get /raw returns (TokenResponse)
}