refactor: error handling return exception message

This commit is contained in:
Juan Rodriguez
2024-05-13 09:22:36 +02:00
parent 9564559610
commit b20417d579
7 changed files with 26 additions and 27 deletions
+4 -4
View File
@@ -2,8 +2,9 @@ require "kemal"
module App
class BadRequestException < Kemal::Exceptions::CustomException
def initialize(context)
def initialize(context, message = Hash(String, String))
context.response.status_code = 400
context.response.print({ "error" => message }.to_json)
super(context)
end
end
@@ -16,11 +17,10 @@ module App
end
class UnprocessableEntityException < Kemal::Exceptions::CustomException
def initialize(context, @content = "")
def initialize(context, message = Hash(String, String))
context.response.status_code = 422
context.response.print({ "error" => message }.to_json)
super(context)
end
getter :content
end
end