Open wozza35 opened 1 year ago
I am thinking this might have happened due to a refactor. probably best to update the documentation, unless we're really missing out on something...
Might be related to my change with returning multiple errors, so either we need to reconsider that change or update the documentation.
@davidwessman Can you update the documentation ?
EDIT Now I realized the point about the different interfaces of param
for ParamMissing
vs ParamInvalid
.
So my answer was probably not on point - sorry.
So it seems like these errors have always used different interfaces for the params.
ParamInvalid
is initialized like:
https://github.com/Apipie/apipie-rails/blob/7cc859ec4f5727e08c6ebeab47c9a90220e57623/lib/apipie/validator.rb#L75-L77
ParamMissing
is initialized like:
So it seems like it would make sense the change the ParamInvalid
error to receive the whole ParamDescription
as well.
But that seems like breaking change :/
Inconsistent interface isn't ideal, I convey, but considering the little audience of this gem. I'm not sure its worth fixing.
I guess if enough people vote that its worth it. otherwise, I think this is really minor. or at least, I don't see what exact problem is causes.
It is suggested in the documentation to rescue both
ParamMissing
andParamInvalid
exceptions by rescuing from theApipie::ParamError
superclass. However, the interface of these two sub-classes is different.For example, I'm trying to return a custom error JSON message in the case of a param error:
ParamMissing#param
returns an instance ofApipie::ParamDescription
, whereasParamInvalid#param
returns a symbol. So, If the parameter is not an Array:If the parameter is missing:
I realize I can rescue the error classes separately or make use of meta programming, but it seems like this might be unintentional behaviour?