Replies: 2 comments
-
@kralewitz sorry for the delay. You are correct that this isn't currently easy to do in one service. Both your options would work in my opinion. I almost made the NewError function a property of the API when designing it, but since handler functions don't have access to the API directly and the |
Beta Was this translation helpful? Give feedback.
-
Moving this to a discussion as this needs a design and I'm not sure how to approach it, feel free to discuss and provide a design that handles the utility error functions. |
Beta Was this translation helpful? Give feedback.
-
Hello, I have a single go program which provides two separate
huma.API
s. For one API, I'd like to keep the RFC9457 error responses which are used by default, but for the other API I need to use a custom error response due to legacy reasons. I'd also like to use the default validators for both APIs.Now since the
NewError
function is defined as a package-level var, it looks like there's no easy way to use a different default error response for each API instance and I basically have two options:Is there another way that I missed?
If not, might I suggest embedding the
NewError
function directly in thehuma.API
instance, maybe during initialization via theConfig
struct? Looking at the source code, it seems to be used in theRegister
andWriteErr
functions, which both have access to theAPI
instance. This would however leave the package-levelError*
utility functions tied only to the globalNewError
func.Anyway, thanks for the work you've put into the framework, I like the features very much and this is the only minor hiccup I have run into so far :)
Beta Was this translation helpful? Give feedback.
All reactions