-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce client-side validation on methods #293
Comments
* #311 - Parse ISO 8601 date(time) strings as Instant * Add serialize test * Add concept of precision to date time properties of entities * Improve comparability by introducing valid and invalid PrecisionDateTime * Use correct descriptor name * Ensure that StartOfDay is serialized correctly * Update kDoc * Serialize invalid values as null * Expect scheduledAt as Instant instead of as String * Add last missing type replacements * #293 Add client-side validation for scheduling date * Remove erroneous kDoc
Having seen this in some newly added methods, I wonder if we should really do this everywhere, especially in cases where the server would fail safely, anyway. For example, any endpoint that accepts a If these allowed limits ever change, whether it is between Mastodon versions or even by individual instances being configured manually, our library could not be fully used on some instances unless updated. I do think that this is a good thing to do for cases where we are sure that the request would fail with some 4xx response or at least lead to very unexpected results, like trying to schedule a post in the past or with a string that cannot be parsed into any valid timestamp - but I doubt we should do it all across the board. |
Oh, I did not know that! I thought it would fail with a higher limit. That was my whole reason for doing client-side validation: To fail the request before it goes over the network to save resources. If that turns out to not be the case, I’m also in favour of rolling those checks back.
Yep, excellent point. I did think about that possibility from time to time but never talked about it. Good that you raise it! |
In #287 and #286, I started introducing client-side validation for some very easy to catch errors defined by the Mastodon documentation, such as “input length should only be 80 characters”, “input should not contain spaces”, “input should not contain #”, and so on.
We want to go through all existing methods (“methods” meaning the methods in
bigbone/src/main/kotlin/social/bigbone/api/method
) and check where it could make sense to add client-side validation.For the client-side validation, we want to return
IllegalArgumentException
s. For easy ones, we should use Kotlin’srequire
and amessage
lambda that we pass.Example:
For the slightly harder ones where we deal with optional parameters that may or may not be null, but if they’re non-null need to follow certain criteria, we write our own checks, such as:
Originally posted by @andregasser in #287 (comment)
The text was updated successfully, but these errors were encountered: