feat: add typed error message templates and stable replay snapshots
This commit is contained in:
48
examples/contracts/errorParams.api
Normal file
48
examples/contracts/errorParams.api
Normal file
@@ -0,0 +1,48 @@
|
||||
syntax = "v1"
|
||||
|
||||
errorCatalog CommonErrors (
|
||||
defaultStatus: 200
|
||||
errors: {
|
||||
"TextTooLong": {
|
||||
"key": "TEXT_TOO_LONG",
|
||||
"code": 400002,
|
||||
"message": "{label}不能超过{max}个字符",
|
||||
"params": [
|
||||
{"name": "label", "type": "string", "example": "企业名称"},
|
||||
{"name": "max", "type": "int", "example": 100}
|
||||
]
|
||||
},
|
||||
"UsernameInvalid": {"key": "USERNAME_INVALID", "code": 400003, "message": "用户名格式不正确"},
|
||||
"ResourceDenied": {
|
||||
"key": "RESOURCE_DENIED", "status": 403, "code": 403001,
|
||||
"message": "{label}不可用",
|
||||
"params": [{"name": "label", "type": "string", "example": "资源"}]
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
response CommonResponse (
|
||||
codeType: int32
|
||||
successCode: 0
|
||||
errorCode: 9999
|
||||
body: {"code": "${code}", "msg": "${message}", "data": "${data}"}
|
||||
dataMode: always
|
||||
)
|
||||
|
||||
type TokenResponse {
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
@server (
|
||||
group: account
|
||||
response: CommonResponse
|
||||
errors: TextTooLong, UsernameInvalid, ResourceDenied
|
||||
)
|
||||
service error-params-api {
|
||||
@handler token
|
||||
post /token returns (TokenResponse)
|
||||
|
||||
@response raw
|
||||
@handler raw
|
||||
get /raw returns (TokenResponse)
|
||||
}
|
||||
Reference in New Issue
Block a user