feat: release v0.26 portable i18n and presentation adapters
This commit is contained in:
@@ -53,6 +53,15 @@ func (c *Context) writeResult(result response.Result) (err error) {
|
||||
if encoder == nil {
|
||||
encoder = response.Default()
|
||||
}
|
||||
if c.errorLocalizer != nil && result.Err != nil {
|
||||
if message, ok := c.localizedMessage(result.Err); ok {
|
||||
result.MessageOverride = &message
|
||||
if c.failure != nil {
|
||||
c.failure = c.failure.Clone()
|
||||
c.failure.Message = message
|
||||
}
|
||||
}
|
||||
}
|
||||
payload, err := encoder.Encode(result)
|
||||
if err != nil {
|
||||
return apierrors.Internal(err)
|
||||
@@ -69,6 +78,17 @@ func (c *Context) writeResult(result response.Result) (err error) {
|
||||
return c.WriteResponse(payload.Status, payload.Header, payload.Body)
|
||||
}
|
||||
|
||||
// Presentation adapter failures cannot turn a business result into a new error.
|
||||
func (c *Context) localizedMessage(err error) (message string, ok bool) {
|
||||
defer func() {
|
||||
if recover() != nil {
|
||||
message, ok = "", false
|
||||
}
|
||||
}()
|
||||
registry := c.ErrorRegistry()
|
||||
return c.errorLocalizer.Localize(c.Context(), registry, registry.Resolve(err))
|
||||
}
|
||||
|
||||
// RespondStatus uses the current response format and error catalog, but keeps
|
||||
// the explicit HTTP status even if a catalog/custom encoder selects another.
|
||||
// This is useful for protocol endpoints such as health probes. Ordinary
|
||||
|
||||
Reference in New Issue
Block a user