feat(smalltrip,problem): make WithDetail, WithDetailf and WithError append message if there is already one

This commit is contained in:
Guz
2025-07-30 19:15:08 -03:00
parent b6a41a168b
commit e158aebbd5

View File

@@ -140,19 +140,23 @@ func WithStatus(s int) Option {
func WithDetail(d string) Option { func WithDetail(d string) Option {
return func(p *RegisteredProblem) { return func(p *RegisteredProblem) {
p.DetailMessage = d if p.DetailMessage != "" {
p.DetailMessage = fmt.Sprintf("%s: %s", p.DetailMessage, d)
} else {
p.DetailMessage = d
}
} }
} }
func WithDetailf(f string, args ...any) Option { func WithDetailf(f string, args ...any) Option {
return func(p *RegisteredProblem) { return func(p *RegisteredProblem) {
p.DetailMessage = fmt.Sprintf(f, args...) WithDetail(fmt.Sprintf(f, args...))(p)
} }
} }
func WithError(err error) Option { func WithError(err error) Option {
return func(p *RegisteredProblem) { return func(p *RegisteredProblem) {
p.DetailMessage = err.Error() WithDetail(err.Error())(p)
} }
} }