-
Notifications
You must be signed in to change notification settings - Fork 1
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
The current implementation of build_json
requires that no exceptions be thrown
#24
Comments
Options:
Advantages:
Disadvantages:
Feel free to edit this comment to add options, advantages, and disavantages. However, keep the lists in order so that we can reference them in a discussion below. If an option is to be dismissed, |
There is a third option, storing to an object instead of an IO, then doing I think the first option is the better one. |
Isn't that Option |
I prefer option def build_json(context : HTTP::Server::Context)
buffer = IO::Memory.new
JSON.build buffer do |json|
json.object do
json.field("data") { json.object { yield json } }
end
end
rescue e
raise InternalServerError.new context, cause: e
else
IO.copy buffer, context.response
end |
JSON api is right about not having both |
The current implementation of
build_json
requires that no exceptions be thrown while the response is being built. Until now, the only resolution to this I could think of was building to an intermediary IO and copying tocontext.response
after it's built. That would be a big performance hit in a crucial spot. However, talking another look at my implementation I was thinking that there is one alternative, although it is less than ideal....suggestions are welcome, but I'd recommend we discuss this in a separate PR, so that I can also begin work on other routes while we work out the details.I realize this would require specifying a partial succesful response, but there's no way to rewind an
HTTP::Server::Response
because it's streamed out to the client on the fly.Originally posted by @dscottboggs in #10
For the package routes, I (think) I successfully avoided cases which raise, so that's an option as well, but it's...fragile, and I don't like it, especially not long-term
The text was updated successfully, but these errors were encountered: