subrouters

This commit is contained in:
2026-01-12 04:54:53 -07:00
parent a72fd9e0e8
commit 0d6af06d65
27 changed files with 950 additions and 174 deletions
+25
View File
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"net/http"
"ruben/inventory2/internal/consts"
"strings"
)
@@ -133,3 +134,27 @@ func GetError(err error) (e ErrorResponse, ok bool) {
ok = errors.As(err, &e)
return e, ok
}
// error wrapping utilities
func ErrorFromConstant(err error) error {
cerr := err
for cerr != nil {
switch cerr {
case consts.ErrNotFound:
return NotFound()
case consts.ErrConflict:
return Conflict()
}
uerr, ok := cerr.(interface {
Unwrap() error
})
if !ok {
return err
}
cerr = uerr.Unwrap()
}
return err
}