-
Notifications
You must be signed in to change notification settings - Fork 9
Add useful properties to error object #80
Comments
There is no such thing as "the property on which error occurred". Sometimes the error is not caused by any particular property, any particular facet etc. Let me provide an example of how to use this mechanism: Here we define an invalid type:
Now lets try to find out the source(s) of the error:
Here is the output:
Here Note: you can use
It is recommended to use validation path, but if you wish to see the constraint and the error is caused by a constraint, you can obtain it as a source. For the example above:
Output:
Same as above, it can happen that there is no facet involved, but if there is one you can obtain the value:
Output:
In case of the
Copy-pasting the linked sample here to make it more clear:
In this example,
is an initial type description, it could be RAML code instead. The value of
|
thanks for the pointers. your solution works fine for validation errors like For example:
|
another slightly different one with dates:
|
@jstoiko facetName() and value() methods has meaning for the subclasses of You can analyze and support the whole hierarchy if you want, but there is like 30 classes in there, and there are other sources, not only restrictions. As I said, please use the error message and validation path to find out the source. If there is no path, report the issue to the current root. |
It would be nice if the error object (i.e. Status) returned:
error.source.name
, sometimes it'serror.vp.name
[1]type
,required
,pattern
,minLength
, etcstring
,true
,[a-z]+
,1
, etc[1] if the property is not available (i.e. single type), maybe it could be the name of the variable that was assigned to the type, e.g.
personType
in the 1st exampleThe text was updated successfully, but these errors were encountered: