translations_controller.rb 887 B

123456789101112131415161718192021222324252627
  1. # frozen_string_literal: true
  2. class Api::V1::Statuses::TranslationsController < Api::V1::Statuses::BaseController
  3. before_action -> { doorkeeper_authorize! :read, :'read:statuses' }
  4. before_action :set_translation
  5. rescue_from TranslationService::NotConfiguredError, with: :not_found
  6. rescue_from TranslationService::UnexpectedResponseError, with: :service_unavailable
  7. rescue_from TranslationService::QuotaExceededError do
  8. render json: { error: I18n.t('translation.errors.quota_exceeded') }, status: 503
  9. end
  10. rescue_from TranslationService::TooManyRequestsError do
  11. render json: { error: I18n.t('translation.errors.too_many_requests') }, status: 503
  12. end
  13. def create
  14. render json: @translation, serializer: REST::TranslationSerializer
  15. end
  16. private
  17. def set_translation
  18. @translation = TranslateStatusService.new.call(@status, content_locale)
  19. end
  20. end