refactor: error handling return exception message
This commit is contained in:
+4
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user