From faedd0bc7acf8b077f14023aa9ec473da81610e1 Mon Sep 17 00:00:00 2001 From: Juan Rodriguez Date: Sun, 14 Jul 2024 09:26:38 +0200 Subject: [PATCH] fix: missing errors content type --- app/lib/errors.cr | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/lib/errors.cr b/app/lib/errors.cr index 287b48a..833b841 100644 --- a/app/lib/errors.cr +++ b/app/lib/errors.cr @@ -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)