OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
fix content type in error handling
ulferts0a9a7f02d1a9
diff --git a/lib/api/root.rb b/lib/api/root.rbindex d06d515575d..4544cfd758b 100644--- a/lib/api/root.rb+++ b/lib/api/root.rb@@ -37,9 +37,18 @@ module APIparser :json, API::V3::Parser.new- error_representer ::API::V3::Errors::ErrorRepresenter+ error_representer ::API::V3::Errors::ErrorRepresenter, 'hal+json'authentication_scope OpenProject::Authentication::Scope::API_V3+ OpenProject::Authentication.handle_failure(scope: API_V3) do |warden, _opts|+ e = grape_error_for warden.env, self+ error_message = I18n.t('api_v3.errors.code_401_wrong_credentials')+ api_error = ::API::Errors::Unauthenticated.new error_message+ representer = ::API::V3::Errors::ErrorRepresenter.new api_error++ e.error_response status: 401, message: representer.to_json, headers: warden.headers, log: false+ end+version 'v3', using: :path domount API::V3::Rootenddiff --git a/lib/api/root_api.rb b/lib/api/root_api.rbindex 37586aaeb79..f6828f69ac1 100644--- a/lib/api/root_api.rb+++ b/lib/api/root_api.rb@@ -193,43 +193,20 @@ module APIendend- def self.error_representer(klass = nil)- if klass- @error_representer = klass-- # Have the representer class available in the instances- # via a helper.- helpers do- define_method(:error_representer, -> { klass })- end+ def self.error_representer(klass, content_type)+ # Have the vars available in the instances via helpers.+ helpers do+ define_method(:error_representer, -> { klass })+ define_method(:error_content_type, -> { content_type })end-- @error_representerend- def self.authentication_scope(sym = nil)- if sym- @authentication_scope = sym-- # Have the representer class available in the instances- # via a helper.- helpers do- define_method(:authentication_scope, -> { sym })- end+ def self.authentication_scope(sym)+ # Have the scope available in the instances+ # via a helper.+ helpers do+ define_method(:authentication_scope, -> { sym })end-- @authentication_scope- end-- ##- # Return JSON error response on authentication failure.- OpenProject::Authentication.handle_failure(scope: API_V3) do |warden, _opts|- e = grape_error_for warden.env, self- error_message = I18n.t('api_v3.errors.code_401_wrong_credentials')- api_error = ::API::Errors::Unauthenticated.new error_message- representer = error_representer.new api_error-- e.error_response status: 401, message: representer.to_json, headers: warden.headers, log: falseenderror_response ActiveRecord::RecordNotFound, ::API::Errors::NotFound, log: falsediff --git a/lib/api/utilities/grape_helper.rb b/lib/api/utilities/grape_helper.rbindex c32e123985e..068d18d0b4d 100644--- a/lib/api/utilities/grape_helper.rb+++ b/lib/api/utilities/grape_helper.rb@@ -69,6 +69,7 @@ module APIoriginal_exception = $!representer = error_representer.new eresp_headers = instance_exec &headers+ env['api.format'] = error_content_typeif log == trueOpenProject.logger.error original_exception, reference: :APIv3diff --git a/modules/bcf/app/controllers/bcf/api/root.rb b/modules/bcf/app/controllers/bcf/api/root.rbindex b7b661fb042..e7dc6b3a968 100644--- a/modules/bcf/app/controllers/bcf/api/root.rb+++ b/modules/bcf/app/controllers/bcf/api/root.rb@@ -39,7 +39,7 @@ module Bcf::APIdefault_format :json- error_representer ::Bcf::API::V2_1::Errors::ErrorRepresenter+ error_representer ::Bcf::API::V2_1::Errors::ErrorRepresenter, :jsonerror_formatter :json, ::Bcf::API::ErrorFormatter::Jsonauthentication_scope OpenProject::Authentication::Scope::BCF_V2_1