You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
However, Promise.reject(), just like a regular throw, is supposed to accept Error objects. For various historical reasons, throwalso accepts non-error objects (so you can throw a string, ie throw 'Something'). Same with Promise.reject(). However, this is considered an anti-pattern, and Standard linters flag this as an error.
Now, a validation result is currently not an Error instance, it's its own object.
So the question before us is this: What's the best way to turn a validation result into an Error instance? I'm currently doing something like:
but that feels hack-y. We should actually consider a .error getter method on our validation result instances. (That would return a nice error instance, populated with a stringified validation error message.) So that the use can do:
returnPromise.reject(validation.error)
The text was updated successfully, but these errors were encountered:
A typical usage for
json-document
validation is something like in jose/JWKSet.importKeys()
:However,
Promise.reject()
, just like a regularthrow
, is supposed to accept Error objects. For various historical reasons,throw
also accepts non-error objects (so you can throw a string, iethrow 'Something'
). Same with Promise.reject(). However, this is considered an anti-pattern, and Standard linters flag this as an error.Now, a validation result is currently not an Error instance, it's its own object.
So the question before us is this: What's the best way to turn a validation result into an Error instance? I'm currently doing something like:
but that feels hack-y. We should actually consider a
.error
getter method on our validation result instances. (That would return a nice error instance, populated with a stringified validation error message.) So that the use can do:The text was updated successfully, but these errors were encountered: