Skip to content

Commit

Permalink
Fix bug in the exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Giorgi Kavrelishvili authored and Giorgi Kavrelishvili committed May 12, 2024
1 parent 43bc8ac commit 698c374
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ class IndexController < Grip::Controllers::Http
end

class Application < Grip::Application
def initialize(environment : String, serve_static : Bool)
def initialize(environment : String)
# By default the environment is set to "development" and serve_static is false.
super(environment, serve_static)
super(environment)

scope "/api" do
scope "/v1" do
Expand All @@ -84,7 +84,7 @@ class Application < Grip::Application
end
end

app = Application.new(environment: "development", serve_static: false)
app = Application.new(environment: "development")
app.run
```

Expand Down
6 changes: 3 additions & 3 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ end

class ErrorApplication < Grip::Application
def initialize
super(environment: "test", serve_static: false)
super(environment: "test")

exception Grip::Exceptions::NotFound, ErrorController
end
Expand All @@ -24,7 +24,7 @@ end

class HttpApplication < Grip::Application
def initialize
super(environment: "test", serve_static: false)
super(environment: "test")

get "/", ExampleController
get "/:id", ExampleController, as: :index
Expand All @@ -37,7 +37,7 @@ end

class WebSocketApplication < Grip::Application
def initialize
super(environment: "test", serve_static: false)
super(environment: "test")

ws "/", MatchController
end
Expand Down
3 changes: 2 additions & 1 deletion src/grip/handlers/exception.cr
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ module Grip
context.response.status_code = status_code
context.exception = exception

updated_context = @handlers[exception.class.name].call(context)
context.response.close
@handlers[exception.class.name].call(context)
updated_context
else
if status_code.in?(400..599)
context.response.status_code = status_code
Expand Down

0 comments on commit 698c374

Please sign in to comment.