feat: release v0.26 portable i18n and presentation adapters
This commit is contained in:
@@ -187,6 +187,9 @@ func (f *Formatter) Value(r Result) map[string]any {
|
||||
if isError && r.BusinessCode != nil {
|
||||
code, message = r.BusinessCode, r.Message
|
||||
}
|
||||
if r.MessageOverride != nil {
|
||||
message = *r.MessageOverride
|
||||
}
|
||||
body := c.Body
|
||||
if isError && c.ErrorBody != nil {
|
||||
body = c.ErrorBody
|
||||
|
||||
@@ -16,6 +16,10 @@ type Result struct {
|
||||
Err error
|
||||
BusinessCode any
|
||||
Failed bool
|
||||
// MessageOverride is optional localized presentation. Message remains the
|
||||
// canonical catalog text for validation. Custom protocols opt in by calling
|
||||
// PublicMessage; fixed acknowledgments remain under their encoder's control.
|
||||
MessageOverride *string
|
||||
// PreserveStatus keeps an explicit protocol status through catalog mapping
|
||||
// and HTTP output (for example, readiness must remain 503 when unhealthy).
|
||||
PreserveStatus bool
|
||||
@@ -24,6 +28,13 @@ type Result struct {
|
||||
// IsError preserves failure semantics independently of the HTTP status.
|
||||
func (r Result) IsError() bool { return r.Failed || r.Err != nil || r.Status >= 400 }
|
||||
|
||||
func (r Result) PublicMessage() string {
|
||||
if r.MessageOverride != nil {
|
||||
return *r.MessageOverride
|
||||
}
|
||||
return r.Message
|
||||
}
|
||||
|
||||
// Payload is a complete response. Encoders must be safe for concurrent use.
|
||||
// Status and headers are intentionally part of the contract: callback protocols
|
||||
// may acknowledge an error using a different HTTP status or media type.
|
||||
|
||||
Reference in New Issue
Block a user