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

Revamp error handler/action #903

Merged
merged 4 commits into from
Sep 16, 2019
Merged

Revamp error handler/action #903

merged 4 commits into from
Sep 16, 2019

Conversation

paulcsmith
Copy link
Member

@paulcsmith paulcsmith commented Sep 16, 2019

Part of #868. See that issue for details

Copy link
Member Author

@paulcsmith paulcsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gonna try to merge this fairly quickly so I can do the Lucky CLI side of things and test this in some real world scenarios


private class FakeErrorAction < Lucky::ErrorAction
def handle_error(error : FakeError) : Lucky::Response
def render(error : CustomError) : Lucky::Response
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed handle_error to render. I think this is simpler and reads better

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause any issues with calling the render method from actions? I guess it shouldn't if their argument types are different.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will work (or it wouldn't compile) but this could be kind of confusing or lead to unexpected compile errors since there could be tons of different overloads. I think for now I'll rename it render_error

I've been thinking of renaming render to html or something. Since everything else (like json) has the type in the name. E.g. html Users::IndexPage, users: UserQuery.new

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea of using html. It's an easy change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! I like it. And should be a pretty easy thing to upgrade

plain_text "This is not a debug page", status: 500
end

def report(error : Exception)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an abstract report method for reporting methods however you want!

private def call_error_action(context : HTTP::Server::Context, error : Exception) : HTTP::Server::Context
status_code = status_code_by_error(error)
context.response.status_code = status_code
settings.logger.error(exception: error.inspect_with_backtrace)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always log the exception

Copy link
Member

@jwoertink jwoertink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks all good here from what I can tell. Feel free to merge, and we can fix up whatever issues come up.

it "calls the report method on the error action" do
io = IO::Memory.new
FakeErrorAction.temp_config(output: io) do
handle_error(error: CustomError.new) do |_context, _output|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be render too?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, nevermind. I see this method from below.


private class FakeErrorAction < Lucky::ErrorAction
def handle_error(error : FakeError) : Lucky::Response
def render(error : CustomError) : Lucky::Response
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this cause any issues with calling the render method from actions? I guess it shouldn't if their argument types are different.

Copy link
Member Author

@paulcsmith paulcsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good point about render. I'll change that up for now and maybe revisit later if we rename render (for html pages) to something else


private class FakeErrorAction < Lucky::ErrorAction
def handle_error(error : FakeError) : Lucky::Response
def render(error : CustomError) : Lucky::Response
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will work (or it wouldn't compile) but this could be kind of confusing or lead to unexpected compile errors since there could be tons of different overloads. I think for now I'll rename it render_error

I've been thinking of renaming render to html or something. Since everything else (like json) has the type in the name. E.g. html Users::IndexPage, users: UserQuery.new

@paulcsmith paulcsmith merged commit a60c804 into master Sep 16, 2019
@paulcsmith paulcsmith deleted the pcs/868-redo-handler branch September 16, 2019 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants