fix: missing errors content type
This commit is contained in:
@@ -3,6 +3,7 @@ require "kemal"
|
||||
module App
|
||||
class BadRequestException < Kemal::Exceptions::CustomException
|
||||
def initialize(context, message : String)
|
||||
context.response.content_type = "application/json"
|
||||
context.response.status_code = 400
|
||||
context.response.print({ "error" => message }.to_json)
|
||||
super(context)
|
||||
@@ -11,13 +12,16 @@ module App
|
||||
|
||||
class UnauthorizedException < Kemal::Exceptions::CustomException
|
||||
def initialize(context)
|
||||
context.response.content_type = "application/json"
|
||||
context.response.status_code = 401
|
||||
context.response.print({ "error" => "Unauthorized access" }.to_json)
|
||||
super(context)
|
||||
end
|
||||
end
|
||||
|
||||
class ForbiddenException < Kemal::Exceptions::CustomException
|
||||
def initialize(context)
|
||||
context.response.content_type = "application/json"
|
||||
context.response.status_code = 403
|
||||
context.response.print({ "error" => "Access not allowed" }.to_json)
|
||||
super(context)
|
||||
@@ -26,13 +30,16 @@ module App
|
||||
|
||||
class NotFoundException < Kemal::Exceptions::CustomException
|
||||
def initialize(context)
|
||||
context.response.content_type = "application/json"
|
||||
context.response.status_code = 404
|
||||
context.response.print({ "error" => "Resource not found" }.to_json)
|
||||
super(context)
|
||||
end
|
||||
end
|
||||
|
||||
class UnprocessableEntityException < Kemal::Exceptions::CustomException
|
||||
def initialize(context, message : Hash(String, Array(String)))
|
||||
context.response.content_type = "application/json"
|
||||
context.response.status_code = 422
|
||||
context.response.print({ "errors" => message }.to_json)
|
||||
super(context)
|
||||
|
||||
Reference in New Issue
Block a user