From f6613d6e910b32a3efde3424965a86a5ed9c02d2 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Fri, 2 Dec 2022 20:45:46 -0800 Subject: [PATCH] Add TooManySkillsOfTypeError --- app/controllers/api/v1/api_controller.rb | 1 + app/errors/api/v1/TooManySkillsOfTypeError.rb | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 app/errors/api/v1/TooManySkillsOfTypeError.rb diff --git a/app/controllers/api/v1/api_controller.rb b/app/controllers/api/v1/api_controller.rb index e9dcb95..a019f99 100644 --- a/app/controllers/api/v1/api_controller.rb +++ b/app/controllers/api/v1/api_controller.rb @@ -12,6 +12,7 @@ module Api::V1 rescue_from Api::V1::SameFavoriteUserError, with: :render_unprocessable_entity_response rescue_from Api::V1::FavoriteAlreadyExistsError, with: :render_unprocessable_entity_response rescue_from Api::V1::NoJobProvidedError, with: :render_unprocessable_entity_response + rescue_from Api::V1::TooManySkillsOfTypeError, with: :render_unprocessable_entity_response rescue_from Api::V1::UnauthorizedError, with: :render_unauthorized_response rescue_from ActionController::ParameterMissing, with: :render_unprocessable_entity_response diff --git a/app/errors/api/v1/TooManySkillsOfTypeError.rb b/app/errors/api/v1/TooManySkillsOfTypeError.rb new file mode 100644 index 0000000..873a452 --- /dev/null +++ b/app/errors/api/v1/TooManySkillsOfTypeError.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +module Api + module V1 + class TooManySkillsOfTypeError < StandardError + def initialize(data) + @data = data + end + + def http_status + 422 + end + + def code + 'too_many_skills_of_type' + end + + def message + 'You can only have up to 2 skills of type' + end + + def to_hash + { + message: message, + code: code, + idea_id: @data[:skill_type] + } + end + end + end +end