f05a12a880
Posts, like 8661f4724aa9, can go missing if the account or post was removed. In this case, the API returns data like this: ```json { "data": { "post": null } } ``` When this happens, we can detect it because the parsed response now has a nil value: `response.data.post == nil` and construct an `EmptyPage` instead of a `Page`. The `Articles::Show` action can then render conditionally based on if the response from `PageConverter` is a `Page` or an `EmptyPage`.
12 lines
291 B
Crystal
12 lines
291 B
Crystal
module ActionHelpers
|
|
private def action_context(path = "/")
|
|
io = IO::Memory.new
|
|
request = HTTP::Request.new("GET", path)
|
|
response = HTTP::Server::Response.new(io)
|
|
HTTP::Server::Context.new(request, response)
|
|
end
|
|
|
|
private def params
|
|
{} of String => String
|
|
end
|
|
end
|