2026-05-19 11:00:28 +00:00
|
|
|
package response
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
errs "gateway/internal/library/errors"
|
|
|
|
|
"gateway/internal/library/errors/code"
|
2026-05-19 12:56:32 +00:00
|
|
|
"gateway/internal/library/validate"
|
2026-05-19 11:00:28 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// RequestErrScope is used when mapping httpx.Parse / validation errors to business codes.
|
|
|
|
|
// Set once in main (e.g. response.RequestErrScope = code.Facade).
|
|
|
|
|
var RequestErrScope = code.Facade
|
|
|
|
|
|
|
|
|
|
// WrapRequestError maps binding / validation failures to InputInvalidFormat (HTTP 400).
|
|
|
|
|
// Business *errs.Error values are returned unchanged.
|
|
|
|
|
func WrapRequestError(err error) error {
|
|
|
|
|
if err == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
if errs.FromError(err) != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
2026-05-19 12:56:32 +00:00
|
|
|
if ve, ok := validate.AsErrors(err); ok {
|
|
|
|
|
return ve.ToBusinessError(RequestErrScope)
|
|
|
|
|
}
|
2026-05-19 11:00:28 +00:00
|
|
|
|
|
|
|
|
return errs.For(RequestErrScope).InputInvalidFormat(err.Error())
|
|
|
|
|
}
|