Giter Club home page Giter Club logo

Comments (8)

stevenharman avatar stevenharman commented on May 26, 2024

A similar topic was brought up not too long ago in #78, but it was determined it we didn't need to expose the actual #encoded_payload. In your case, I can understand to expose the #payload_size while keeping the actual encoded payload an implementation detail.

An alternative idea: What if we enhance the #validate_payload to raise a PayloadTooLargeError error which has more details about the exact size. So you could directly use that if you wanted. And we could go a step further and also have the #valid? method shove the rescued exception's #message into an array of errors, which we expose via a #errors method. Thoughts?

from grocer.

mbillard avatar mbillard commented on May 26, 2024

I'd rather avoid using exceptions for flow control. If there's no particular reason for hiding these methods, I would simply expose them.

Not exposing encoded_payload is fine though.

Using #errors could also work, but it seems like too much trouble and indirect.

from grocer.

stevenharman avatar stevenharman commented on May 26, 2024

I'd rather avoid using exceptions for flow control.

I agree completely, which is why Grocer would expose a #valid? method for you to use. Internally we'd leverage exceptions, but we're not switching behavior based on them. And internally we do consider a notification with too large a body to be the exceptional case, rather than the expected case. But again, from the consumer's (i.e., your code's) perspective, it's just a predicate method, as per usual. ;)

I was thinking the #valid? + #errors would be nice b/c it would prevent consumers from having to know all of the various ways that something might be invalid. (e.g., no payload, payload too large, etc.)

from grocer.

n-studio avatar n-studio commented on May 26, 2024

+1 for #valid? and #errors, but how do you get the bytesize from #errors?

from grocer.

mbillard avatar mbillard commented on May 26, 2024

@n-studio I simply made payload_size public

from grocer.

stevenharman avatar stevenharman commented on May 26, 2024

@n-studio My thinking is: as part of the enhancement to #valid? and exposing #errors, we'd put the current encoded_payload.bytesize into the error message we give to PayloadTooLargeError. Does that make sense?

from grocer.

stevenharman avatar stevenharman commented on May 26, 2024

@mbillard I do still think going with #valid and #errors to be a great option for handling this, but I don't have the need for it now. However, you do need to know that information. If you're up for submitting your changes as a PR, I think we can merge them.

Thoughts?

from grocer.

n-studio avatar n-studio commented on May 26, 2024

@mbillard Yes, I think it's necessary to have payload_size public.

@stevenharman If encoded_payload.bytesize is only in the error message then we need to parse the message to get the size, which would be ugly.
But if payload_size is public, everything is great!

from grocer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.