Skip to content

Commit

Permalink
Respond with error message when some submission attributes cannot be …
Browse files Browse the repository at this point in the history
…converted to UTF-8 (solves #129)
  • Loading branch information
hermanzdosilovic committed Dec 31, 2019
1 parent 3d4df3b commit cdcaa51
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,19 @@ def index
submissions: serializable_submissions.as_json,
meta: pagination_dict(submissions)
}
rescue Encoding::UndefinedConversionError => e
render json: {
error: "some attributes for one or more submissions cannot be converted to UTF-8, use base64_encoded=true query parameter"
}, status: :bad_request
end

def show
render_invalid_field_error and return if has_invalid_field
render json: Submission.find_by!(token: params[:token]), base64_encoded: params[:base64_encoded] == "true", fields: requested_fields
rescue Encoding::UndefinedConversionError => e
render json: {
error: "some attributes for this submission cannot be converted to UTF-8, use base64_encoded=true query parameter"
}, status: :bad_request
end

def create
Expand All @@ -47,9 +55,16 @@ def create

if submission.save
if wait
render_invalid_field_error and return if has_invalid_field
IsolateJob.perform_now(submission)
render json: submission, status: :created, base64_encoded: params[:base64_encoded] == "true", fields: requested_fields
begin
render_invalid_field_error and return if has_invalid_field
IsolateJob.perform_now(submission)
render json: submission, status: :created, base64_encoded: params[:base64_encoded] == "true", fields: requested_fields
rescue Encoding::UndefinedConversionError => e
render json: {
token: submission.token,
error: "some attributes for this submission cannot be converted to UTF-8, use base64_encoded=true query parameter"
}, status: :created
end
else
IsolateJob.perform_later(submission)
render json: submission, status: :created, fields: [:token]
Expand Down

0 comments on commit cdcaa51

Please sign in to comment.