add meaningful error message on upload [fixes ]

This commit is contained in:
Régis Hanol 2013-04-27 20:26:17 +02:00
parent eae2e74152
commit dca2fbcefc
6 changed files with 24 additions and 3 deletions
app/controllers

View file

@ -8,5 +8,11 @@ class UploadsController < ApplicationController
return render status: 415, json: failed_json unless file.content_type =~ /^image\/.+/
upload = Upload.create_for(current_user.id, file, params[:topic_id])
render_serialized(upload, UploadSerializer, root: false)
rescue FastImage::ImageFetchFailure
render status: 422, text: I18n.t("upload.image.fetch_failure")
rescue FastImage::UnknownImageType
render status: 422, text: I18n.t("upload.image.unknown_image_type")
rescue FastImage::SizeNotFound
render status: 422, text: I18n.t("upload.image.size_not_found")
end
end