Skip to content
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

feat: Reject function for Web-Client #2492

Open
zekronium opened this issue Oct 24, 2023 · 0 comments
Open

feat: Reject function for Web-Client #2492

zekronium opened this issue Oct 24, 2023 · 0 comments

Comments

@zekronium
Copy link
Contributor

zekronium commented Oct 24, 2023

Describe the feature

Like HttpRequest.expect(), but inverted, for conditions that would fail the request if met, allowing to set general fail reasons. This should allow to have a more broad “allowed” request result by setting explicit reject() reasons, thus possibly making the code more readable and easier to understand

Can also be named refuse

Use cases

Implementation wise ResponsePredicate can be reused for this aswell for the reject handling
Basic use

    client.getAbs(request)
      .as(BodyCodec.jsonObject())
      .expect(ResponsePredicate.SOME_STATUS)
      .reject(req -> req.headers.contains("bad header"))
      .send()
      .onFailure(v -> {
        System.out.println("I fail if i have `bad header`");
      })

Another behavior where specific status code ranges are accepected, opposed to setting multiple expect(), could be done with one reject()

In a scenario where SC_SUCCESS is fine, but TOO_MANY_REQUESTS would benefit from its own exception message

    client.getAbs(request)
      .as(BodyCodec.jsonObject())
      .expect(ResponsePredicate.SOME_STATUS)
      .reject(req -> req.status == 429, RatelimitException)
      .send()
      .onFailure(v -> {
        System.out.println("I fail if i have `bad header`");
      }).recover(ex -> {
        //more clear error message, isntead of relying on String parsing via ErrorConverter or other means
      });

Contribution

Can implement myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

1 participant