feat: deliver authenticated task APIs, SDK and P1 regression

This commit is contained in:
2026-09-17 07:41:32 +08:00
parent 4f2935e36f
commit 9701b7a071
37 changed files with 3169 additions and 67 deletions

30
internal/fault/fault.go Normal file
View File

@@ -0,0 +1,30 @@
// Package fault 定义不包含数据库或敏感参数的稳定业务错误。
package fault
import "errors"
type Error struct {
Code string `json:"code"`
Message string `json:"message"`
}
func (e *Error) Error() string { return e.Code + ": " + e.Message }
func New(code, message string) *Error { return &Error{Code: code, Message: message} }
func Code(err error) string {
var e *Error
if errors.As(err, &e) {
return e.Code
}
return "UNAVAILABLE"
}
var (
Unauthorized = New("UNAUTHENTICATED", "valid credentials are required")
Forbidden = New("PERMISSION_DENIED", "operation is not allowed")
NotFound = New("NOT_FOUND", "resource not found")
Conflict = New("STATE_CONFLICT", "resource state does not allow this operation")
IdempotencyConflict = New("IDEMPOTENCY_CONFLICT", "idempotency key was used with different content")
Unavailable = New("UNAVAILABLE", "service temporarily unavailable; retry using the original operation identity")
)
func Invalid(message string) error { return New("INVALID_ARGUMENT", message) }