From 698c3745f47186fc32c2a6f56d18cdadafd9c3de Mon Sep 17 00:00:00 2001 From: Giorgi Kavrelishvili Date: Sun, 12 May 2024 11:00:39 +0400 Subject: [PATCH] Fix bug in the exception handler --- README.md | 6 +++--- spec/spec_helper.cr | 6 +++--- src/grip/handlers/exception.cr | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 2615014..f8d2e1e 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 322ccf8..f7ce614 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -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 @@ -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 @@ -37,7 +37,7 @@ end class WebSocketApplication < Grip::Application def initialize - super(environment: "test", serve_static: false) + super(environment: "test") ws "/", MatchController end diff --git a/src/grip/handlers/exception.cr b/src/grip/handlers/exception.cr index 5c1ea32..11ce3de 100644 --- a/src/grip/handlers/exception.cr +++ b/src/grip/handlers/exception.cr @@ -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