Files
bit/app/lib/errors.cr
T
Juan Rodriguez 7f2a27ec79 feat: auth middleware
- CORS headers
- Get all links that belong to user
2024-05-13 22:35:22 +02:00

42 lines
1.1 KiB
Crystal

require "kemal"
module App
class BadRequestException < Kemal::Exceptions::CustomException
def initialize(context, message : String)
context.response.status_code = 400
context.response.print({ "error" => message }.to_json)
super(context)
end
end
class UnauthorizedException < Kemal::Exceptions::CustomException
def initialize(context)
context.response.status_code = 401
super(context)
end
end
class ForbiddenException < Kemal::Exceptions::CustomException
def initialize(context)
context.response.status_code = 403
context.response.print({ "error" => "Access not allowed" }.to_json)
super(context)
end
end
class NotFoundException < Kemal::Exceptions::CustomException
def initialize(context)
context.response.status_code = 404
super(context)
end
end
class UnprocessableEntityException < Kemal::Exceptions::CustomException
def initialize(context, message : Hash(String, Array(String)))
context.response.status_code = 422
context.response.print({ "errors" => message }.to_json)
super(context)
end
end
end