danielgtaylor / danielgtaylor/huma

Localizer for handling error by request header.

Open
#885 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
4.4k
Forks
285
Avg merge
40m
Merged PRs (30d)
1

Description

I got problem when trying to implement Huma to existing project with locales support.
The global function: huma.ErrorFormatter and builtin validator is not designed to transform error message & it's details.
Currently, I have to make a little hack by marshal the error context and make another transformer to unmarshal it.
Do you have any idea to deal with it?

`

huma.ErrorFormatter = func(format string, args ...any) string {
var pluralCount any = 1
switch format {
case validation.MsgExpectedMinProperties, validation.MsgExpectedMaxProperties:
pluralCount = args[0]
}
msg, _ := json.Marshal(&validator.ValidationInfo{
ID: fmt.Sprintf("error:validation:%s", strings.ReplaceAll(format, " ", "_")),
Format: format,
Default: fmt.Sprintf(format, args...),
Args: args,
PluralCount: pluralCount,
})
return string(msg)
}`

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reviewing Huma's global ErrorFormatter and builtin validator behavior, as well as how the request header is expected to select a locale. The issue does not name files or tests, and completion criteria are not agreed; clarify the design for transforming error messages and details without the marshal/unmarshal workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, internationalization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.