feat: add project-owned error catalogs and HTTP 200 failure contracts
This commit is contained in:
36
examples/contracts/errors.api
Normal file
36
examples/contracts/errors.api
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user