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

Raise friendly error with invalid action #291

Merged
merged 3 commits into from Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lucky/action.cr
Expand Up @@ -6,7 +6,7 @@ abstract class Lucky::Action
def initialize(@context : HTTP::Server::Context, @route_params : Hash(String, String))
end

abstract def call : Lucky::Response
abstract def call

include Lucky::ActionDelegates
include Lucky::ContentTypeHelpers
Expand Down
11 changes: 11 additions & 0 deletions src/lucky/renderable.cr
Expand Up @@ -37,6 +37,17 @@ module Lucky::Renderable
response.print
end

private def handle_response(_response : T) forall T
{% raise <<-ERROR

#{@type} returned #{T}, but it must return a Lucky::Response.

Try this...
▸ Make sure to use a method like `render`, `redirect`, or `json` at the end of your action.
▸ If you are using a conditional, make sure all branches return a Lucky::Response.
ERROR %}
end

private def render_text(body)
Lucky::Response.new(context, "text/plain", body)
end
Expand Down
2 changes: 1 addition & 1 deletion src/lucky/routeable.cr
Expand Up @@ -8,7 +8,7 @@ module Lucky::Routeable
{% end %}

macro setup_call_method(body)
def call : Lucky::Response
def call
callback_result = run_before_callbacks

response = if callback_result.is_a?(Lucky::Response)
Expand Down