Add parser error if invalid metadata json

This commit is contained in:
Oliver Günther
2021-07-03 20:49:08 +02:00
parent b94b0e630d
commit f60b86da2d
3 changed files with 3 additions and 2 deletions
@@ -31,8 +31,6 @@
module Attachments
class PrepareUploadContract < CreateContract
validate :validate_direct_uploads_active
# prepared uploads require a filesize to be present
validates :filesize, presence: true
private
@@ -58,6 +58,8 @@ module API
request.params.tap do |params|
params[:metadata] = JSON.parse(params[:metadata]) if params.key?(:metadata)
end
rescue JSON::ParserError
raise ::API::Errors::InvalidRequestBody.new(I18n.t('api_v3.errors.multipart_body_error'))
end
end
@@ -289,6 +289,7 @@ shared_examples 'an APIv3 attachment resource', type: :request, content_type: :j
context 'file is too large' do
let(:file) { mock_uploaded_file(content: 'a' * 2.kilobytes) }
let(:expanded_localization) do
I18n.t('activerecord.errors.messages.file_too_large', count: max_file_size.kilobytes)
end